From f2ffb703445faf4e7e9eb13075dce013e2f0b1cd Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 1 Sep 2010 15:50:04 +0400 Subject: [PATCH 01/15] do not restart daemon on saving settings --- .../daemon/impl/DaemonListeners.java | 24 ++++++------ .../openapi/editor/DocumentRunnable.java | 10 ++++- .../com/intellij/ide/SaveAndSyncHandler.java | 4 +- .../application/impl/ApplicationImpl.java | 2 +- .../components/impl/stores/StorageUtil.java | 4 +- .../openapi/options/SchemesManagerImpl.java | 39 ++++++------------- 6 files changed, 38 insertions(+), 45 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java index 080bbfe74406..1ade3beb6720 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java @@ -39,7 +39,6 @@ import com.intellij.openapi.editor.colors.EditorColorsManager; import com.intellij.openapi.editor.colors.EditorColorsScheme; import com.intellij.openapi.editor.event.*; import com.intellij.openapi.editor.ex.EditorEventMulticasterEx; -import com.intellij.openapi.editor.impl.softwrap.SoftWrapHelper; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.fileEditor.FileEditor; import com.intellij.openapi.fileEditor.FileEditorManager; @@ -315,26 +314,27 @@ public class DaemonListeners implements Disposable { if (LOG.isDebugEnabled()) { LOG.debug("cancelling code highlighting by write action:" + action); } + if (containsDocumentWorthBothering(action)) { + stopDaemon(false); + } + } + + private boolean containsDocumentWorthBothering(Object action) { if (action instanceof DocumentRunnable) { + if (action instanceof DocumentRunnable.IgnoreDocumentRunnable) return false; Document document = ((DocumentRunnable)action).getDocument(); if (!worthBothering(document, ((DocumentRunnable)action).getProject())) { - return; + return false; } } - stopDaemon(false); + return true; } public void writeActionFinished(Object action) { - if (myDaemonCodeAnalyzer.isRunning()) { - return; + if (myDaemonCodeAnalyzer.isRunning()) return; + if (containsDocumentWorthBothering(action)) { + stopDaemon(true); } - if (action instanceof DocumentRunnable) { - Document document = ((DocumentRunnable)action).getDocument(); - if (!worthBothering(document, ((DocumentRunnable)action).getProject())) { - return; - } - } - stopDaemon(true); } } diff --git a/platform/platform-api/src/com/intellij/openapi/editor/DocumentRunnable.java b/platform/platform-api/src/com/intellij/openapi/editor/DocumentRunnable.java index 13fc0b7e8026..8b2133775564 100644 --- a/platform/platform-api/src/com/intellij/openapi/editor/DocumentRunnable.java +++ b/platform/platform-api/src/com/intellij/openapi/editor/DocumentRunnable.java @@ -16,7 +16,7 @@ package com.intellij.openapi.editor; import com.intellij.openapi.project.Project; -import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * @author cdr @@ -25,7 +25,7 @@ public abstract class DocumentRunnable implements Runnable { private final Document myDocument; private final Project myProject; - public DocumentRunnable(@NotNull Document document, Project project) { + public DocumentRunnable(@Nullable Document document, Project project) { myDocument = document; myProject = project; } @@ -37,4 +37,10 @@ public abstract class DocumentRunnable implements Runnable { public Project getProject() { return myProject; } + + public abstract static class IgnoreDocumentRunnable extends DocumentRunnable { + public IgnoreDocumentRunnable() { + super(null, null); + } + } } diff --git a/platform/platform-impl/src/com/intellij/ide/SaveAndSyncHandler.java b/platform/platform-impl/src/com/intellij/ide/SaveAndSyncHandler.java index 4ccb21f13d41..56b4a54cbf56 100644 --- a/platform/platform-impl/src/com/intellij/ide/SaveAndSyncHandler.java +++ b/platform/platform-impl/src/com/intellij/ide/SaveAndSyncHandler.java @@ -105,8 +105,8 @@ public class SaveAndSyncHandler implements ApplicationComponent { return !LaterInvocator.isInModalContext() && !ProgressManager.getInstance().hasModalProgressIndicator(); } - - private static void saveProjectsAndDocuments() { + // made public for tests + public static void saveProjectsAndDocuments() { if (LOG.isDebugEnabled()) { LOG.debug("enter: save()"); } diff --git a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java index 2d759ef532e5..12b3b0641ebe 100644 --- a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java @@ -1018,7 +1018,7 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application myDispatcher.getMulticaster().writeActionFinished(action); } - public void _saveSettings() { // for testing purposes + public void _saveSettings() { // public for testing purposes if (mySaveSettingsIsInProgress.compareAndSet(false, true)) { try { doSave(); diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StorageUtil.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StorageUtil.java index 351e8c9e3d5c..460ad7e1ea7d 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StorageUtil.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StorageUtil.java @@ -25,6 +25,7 @@ import com.intellij.openapi.components.RoamingType; import com.intellij.openapi.components.StateStorage; import com.intellij.openapi.components.TrackingPathMacroSubstitutor; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.editor.DocumentRunnable; import com.intellij.openapi.options.StreamProvider; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectBundle; @@ -101,7 +102,8 @@ public class StorageUtil { file.renameTo(backupFile); } - ApplicationManager.getApplication().runWriteAction(new Runnable() { + // mark this action as modifying the file which daemon analyzer should ignore + ApplicationManager.getApplication().runWriteAction(new DocumentRunnable.IgnoreDocumentRunnable() { public void run() { if (!file.exists()) { file.createParentDirs(); diff --git a/platform/platform-impl/src/com/intellij/openapi/options/SchemesManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/options/SchemesManagerImpl.java index e78104de9b9d..c3ea8ae51948 100644 --- a/platform/platform-impl/src/com/intellij/openapi/options/SchemesManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/options/SchemesManagerImpl.java @@ -20,6 +20,7 @@ import com.intellij.openapi.application.impl.ApplicationImpl; import com.intellij.openapi.components.RoamingType; import com.intellij.openapi.components.impl.stores.StorageUtil; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.editor.DocumentRunnable; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.InvalidDataException; @@ -543,10 +544,7 @@ public class SchemesManagerImpl 0) { + if (myDeletedNames.isEmpty()) { + deleteServerFiles(DELETED_XML); + } + else { for (StreamProvider provider : getEnabledProviders()) { try { StorageUtil.sendContent(provider, getFileFullPath(DELETED_XML), createDeletedDocument(), myRoamingType, true); @@ -791,10 +781,6 @@ public class SchemesManagerImpl Date: Wed, 1 Sep 2010 16:46:14 +0400 Subject: [PATCH 02/15] inspections configurable extension upgraded --- .../daemon/impl/HectorComponent.java | 2 +- .../ex/EditInspectionToolsSettingsAction.java | 2 +- .../codeInspection/ui/ErrorsConfigurable.java | 13 ++++--- .../ui/ErrorsConfigurableProvider.java | 26 +++++++++++++ ...atformInspectionsConfigurableProvider.java | 26 +++++++++++++ ...ctInspectionToolsConfigurableProvider.java | 38 +++++++++++++++++++ .../ex/ConfigurableExtensionPointUtil.java | 24 ++++++++++++ .../options/newEditor/OptionsEditor.java | 13 +++++++ .../options/newEditor/OptionsTree.java | 10 +++++ .../src/META-INF/PlatformLangPlugin.xml | 2 +- .../settings/SpellCheckerSettingsPane.java | 18 ++++----- resources/src/META-INF/IdeaPlugin.xml | 2 +- 12 files changed, 158 insertions(+), 18 deletions(-) create mode 100644 platform/lang-impl/src/com/intellij/profile/codeInspection/ui/ErrorsConfigurableProvider.java create mode 100644 platform/lang-impl/src/com/intellij/profile/codeInspection/ui/PlatformInspectionsConfigurableProvider.java create mode 100644 platform/lang-impl/src/com/intellij/profile/codeInspection/ui/ProjectInspectionToolsConfigurableProvider.java diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/HectorComponent.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/HectorComponent.java index 3337f33f24d7..1792a1f8a927 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/HectorComponent.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/HectorComponent.java @@ -145,7 +145,7 @@ public class HectorComponent extends JPanel { } if (!DaemonCodeAnalyzer.getInstance(myFile.getProject()).isHighlightingAvailable(myFile)) return; final Project project = myFile.getProject(); - final ErrorsConfigurable errorsConfigurable = ErrorsConfigurable.SERVICE.getInstance(project); + final ErrorsConfigurable errorsConfigurable = ErrorsConfigurable.SERVICE.createConfigurable(project); assert errorsConfigurable != null; ShowSettingsUtil.getInstance().editConfigurable(project, errorsConfigurable); } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/EditInspectionToolsSettingsAction.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/EditInspectionToolsSettingsAction.java index a87aaede9709..8ec5e4984a4a 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/EditInspectionToolsSettingsAction.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/EditInspectionToolsSettingsAction.java @@ -93,7 +93,7 @@ public class EditInspectionToolsSettingsAction implements IntentionAction, Icona errorsConfigurable = new IDEInspectionToolsConfigurable(InspectionProjectProfileManager.getInstance(project), InspectionProfileManager.getInstance()); } else { - errorsConfigurable = ErrorsConfigurable.SERVICE.getInstance(project); + errorsConfigurable = ErrorsConfigurable.SERVICE.createConfigurable(project); } return settingsUtil.editConfigurable(project, errorsConfigurable, new Runnable() { public void run() { diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/ErrorsConfigurable.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/ErrorsConfigurable.java index 27710d9329d4..629ed22fe55b 100644 --- a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/ErrorsConfigurable.java +++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/ErrorsConfigurable.java @@ -17,8 +17,9 @@ package com.intellij.profile.codeInspection.ui; import com.intellij.openapi.options.Configurable; -import com.intellij.openapi.options.ShowSettingsUtil; +import com.intellij.openapi.options.ex.ConfigurableExtensionPointUtil; import com.intellij.openapi.project.Project; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -37,10 +38,12 @@ public interface ErrorsConfigurable extends Configurable { } @Nullable - public static ErrorsConfigurable getInstance(Project project) { - ErrorsConfigurable profileConfigurable = ShowSettingsUtil.getInstance().findProjectConfigurable(project, ErrorsConfigurable.class); - if (profileConfigurable != null) return profileConfigurable; - return ShowSettingsUtil.getInstance().findApplicationConfigurable(ErrorsConfigurable.class); + public static ErrorsConfigurable createConfigurable(@NotNull Project project) { + Configurable configurable = ConfigurableExtensionPointUtil.createProjectConfigurableForProvider(project, ErrorsConfigurableProvider.class); + if (configurable == null) { + configurable = ConfigurableExtensionPointUtil.createApplicationConfigurableForProvider(ErrorsConfigurableProvider.class); + } + return (ErrorsConfigurable)configurable; } } } diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/ErrorsConfigurableProvider.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/ErrorsConfigurableProvider.java new file mode 100644 index 000000000000..f8791a5c4cb6 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/ErrorsConfigurableProvider.java @@ -0,0 +1,26 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.profile.codeInspection.ui; + +import com.intellij.openapi.options.ConfigurableProvider; + +/** + * @author nik + */ +public abstract class ErrorsConfigurableProvider extends ConfigurableProvider { + @Override + public abstract ErrorsConfigurable createConfigurable(); +} diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/PlatformInspectionsConfigurableProvider.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/PlatformInspectionsConfigurableProvider.java new file mode 100644 index 000000000000..ca814ea48f03 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/PlatformInspectionsConfigurableProvider.java @@ -0,0 +1,26 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.profile.codeInspection.ui; + +/** + * @author nik + */ +public class PlatformInspectionsConfigurableProvider extends ErrorsConfigurableProvider { + @Override + public ErrorsConfigurable createConfigurable() { + return new PlatformInspectionsConfigurable(); + } +} diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/ProjectInspectionToolsConfigurableProvider.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/ProjectInspectionToolsConfigurableProvider.java new file mode 100644 index 000000000000..779dcdbb9bfd --- /dev/null +++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/ProjectInspectionToolsConfigurableProvider.java @@ -0,0 +1,38 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.profile.codeInspection.ui; + +import com.intellij.profile.codeInspection.InspectionProfileManager; +import com.intellij.profile.codeInspection.InspectionProjectProfileManager; + +/** + * @author nik + */ +public class ProjectInspectionToolsConfigurableProvider extends ErrorsConfigurableProvider { + private InspectionProfileManager myProfileManager; + private InspectionProjectProfileManager myProjectProfileManager; + + public ProjectInspectionToolsConfigurableProvider(InspectionProfileManager profileManager, + InspectionProjectProfileManager projectProfileManager) { + myProfileManager = profileManager; + myProjectProfileManager = projectProfileManager; + } + + @Override + public ErrorsConfigurable createConfigurable() { + return new ProjectInspectionToolsConfigurable(myProfileManager, myProjectProfileManager); + } +} diff --git a/platform/platform-impl/src/com/intellij/openapi/options/ex/ConfigurableExtensionPointUtil.java b/platform/platform-impl/src/com/intellij/openapi/options/ex/ConfigurableExtensionPointUtil.java index 1687263a3815..9bcc119e5809 100644 --- a/platform/platform-impl/src/com/intellij/openapi/options/ex/ConfigurableExtensionPointUtil.java +++ b/platform/platform-impl/src/com/intellij/openapi/options/ex/ConfigurableExtensionPointUtil.java @@ -18,6 +18,7 @@ package com.intellij.openapi.options.ex; import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.options.Configurable; import com.intellij.openapi.options.ConfigurableEP; +import com.intellij.openapi.options.ConfigurableProvider; import com.intellij.openapi.options.OptionalConfigurable; import com.intellij.openapi.project.Project; import com.intellij.util.containers.ContainerUtil; @@ -79,4 +80,27 @@ public class ConfigurableExtensionPointUtil { } throw new IllegalArgumentException("Cannot find configurable of " + configurableClass); } + + @Nullable + public static Configurable createProjectConfigurableForProvider(@NotNull Project project, Class providerClass) { + return createConfigurableForProvider(project.getExtensions(PROJECT_CONFIGURABLES), providerClass); + } + + @Nullable + public static Configurable createApplicationConfigurableForProvider(Class providerClass) { + return createConfigurableForProvider(APPLICATION_CONFIGURABLES.getExtensions(), providerClass); + } + + @Nullable + private static Configurable createConfigurableForProvider(ConfigurableEP[] extensions, Class providerClass) { + for (ConfigurableEP extension : extensions) { + if (extension.providerClass != null) { + final Class aClass = extension.findClassNoExceptions(extension.providerClass); + if (aClass != null && providerClass.isAssignableFrom(aClass)) { + return extension.createConfigurable(); + } + } + } + return null; + } } diff --git a/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsEditor.java b/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsEditor.java index 0b0c63cae1e6..a6f1f8b533fc 100644 --- a/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsEditor.java +++ b/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsEditor.java @@ -243,6 +243,19 @@ public class OptionsEditor extends JPanel implements DataProvider, Place.Navigat }); } + public ActionCallback select(Class configurableClass) { + final Configurable configurable = findConfigurable(configurableClass); + if (configurable == null) { + return new ActionCallback.Rejected(); + } + return select(configurable); + } + + @Nullable + public T findConfigurable(Class configurableClass) { + return myTree.findConfigurable(configurableClass); + } + public ActionCallback select(Configurable configurable) { myFilter.refilterFor("", false, true); return myTree.select(configurable); diff --git a/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsTree.java b/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsTree.java index 8741204fcec7..7f6c662dde0a 100644 --- a/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsTree.java +++ b/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsTree.java @@ -263,6 +263,16 @@ public class OptionsTree extends JPanel implements Disposable, OptionsEditorColl return myConfigurable2Node.get(toSelect); } + @Nullable + public T findConfigurable(Class configurableClass) { + for (Configurable configurable : myConfigurable2Node.keySet()) { + if (configurableClass.isInstance(configurable)) { + return configurableClass.cast(configurable); + } + } + return null; + } + class Renderer extends GroupedElementsRenderer.Tree implements TreeCellRenderer { diff --git a/platform/platform-resources/src/META-INF/PlatformLangPlugin.xml b/platform/platform-resources/src/META-INF/PlatformLangPlugin.xml index 2419020241a0..403bb82b174e 100644 --- a/platform/platform-resources/src/META-INF/PlatformLangPlugin.xml +++ b/platform/platform-resources/src/META-INF/PlatformLangPlugin.xml @@ -79,7 +79,7 @@ - + diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/settings/SpellCheckerSettingsPane.java b/plugins/spellchecker/src/com/intellij/spellchecker/settings/SpellCheckerSettingsPane.java index 4a15eea85615..abe64e8f77dd 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/settings/SpellCheckerSettingsPane.java +++ b/plugins/spellchecker/src/com/intellij/spellchecker/settings/SpellCheckerSettingsPane.java @@ -66,16 +66,16 @@ public class SpellCheckerSettingsPane implements Disposable { public void hyperlinkUpdate(final HyperlinkEvent e) { if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { final OptionsEditor optionsEditor = OptionsEditor.KEY.getData(DataManager.getInstance().getDataContext()); - final ErrorsConfigurable toolsConfigurable = ErrorsConfigurable.SERVICE.getInstance(project); - if (optionsEditor != null && toolsConfigurable != null) { - optionsEditor.select(toolsConfigurable).doWhenDone(new Runnable() { - public void run() { - toolsConfigurable.selectInspectionTool("SpellCheckingInspection"); - } - }); - + if (optionsEditor != null) { + final ErrorsConfigurable errorsConfigurable = optionsEditor.findConfigurable(ErrorsConfigurable.class); + if (errorsConfigurable != null) { + optionsEditor.select(errorsConfigurable).doWhenDone(new Runnable() { + public void run() { + errorsConfigurable.selectInspectionTool("SpellCheckingInspection"); + } + }); + } } - } } }); diff --git a/resources/src/META-INF/IdeaPlugin.xml b/resources/src/META-INF/IdeaPlugin.xml index 89603d037086..1f957e2721a4 100644 --- a/resources/src/META-INF/IdeaPlugin.xml +++ b/resources/src/META-INF/IdeaPlugin.xml @@ -631,7 +631,7 @@ - + From a32c599d25aa71a2e61fa7161084135fccf574f9 Mon Sep 17 00:00:00 2001 From: nik Date: Wed, 1 Sep 2010 16:47:38 +0400 Subject: [PATCH 03/15] inspections configurable extension upgraded --- .../options/colors/ScopeColorsPageFactory.java | 15 ++++++--------- .../idea/copyright/ui/ProjectSettingsPanel.java | 2 +- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/application/options/colors/ScopeColorsPageFactory.java b/platform/lang-impl/src/com/intellij/application/options/colors/ScopeColorsPageFactory.java index 80403e6b6834..cb9d3bc8998b 100644 --- a/platform/lang-impl/src/com/intellij/application/options/colors/ScopeColorsPageFactory.java +++ b/platform/lang-impl/src/com/intellij/application/options/colors/ScopeColorsPageFactory.java @@ -16,20 +16,19 @@ package com.intellij.application.options.colors; +import com.intellij.ide.DataManager; import com.intellij.ide.util.scopeChooser.EditScopesDialog; -import com.intellij.openapi.options.ShowSettingsUtil; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.project.ProjectManager; +import com.intellij.ide.util.scopeChooser.ScopeChooserConfigurable; import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.application.ApplicationBundle; import com.intellij.openapi.options.newEditor.OptionsEditor; -import com.intellij.ide.DataManager; -import com.intellij.ide.util.scopeChooser.ScopeChooserConfigurable; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.project.ProjectManager; import javax.swing.*; import java.awt.*; -import java.awt.event.ActionListener; import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; class ScopeColorsPageFactory implements ColorAndFontPanelFactory { public NewColorAndFontPanel createPanel(ColorAndFontOptions options) { @@ -72,9 +71,7 @@ class ScopeColorsPageFactory implements ColorAndFontPanelFactory { final OptionsEditor optionsEditor = OptionsEditor.KEY.getData(DataManager.getInstance().getDataContext()); if (optionsEditor != null) { try { - final ScopeChooserConfigurable projectConfigurable = - ShowSettingsUtil.getInstance().findProjectConfigurable(project, ScopeChooserConfigurable.class); - optionsEditor.select(projectConfigurable); + optionsEditor.select(ScopeChooserConfigurable.class); } catch (IllegalStateException ex) { EditScopesDialog.editConfigurable(project, null); } diff --git a/plugins/copyright/src/com/maddyhome/idea/copyright/ui/ProjectSettingsPanel.java b/plugins/copyright/src/com/maddyhome/idea/copyright/ui/ProjectSettingsPanel.java index c1dffc8acbc7..1e9820535305 100644 --- a/plugins/copyright/src/com/maddyhome/idea/copyright/ui/ProjectSettingsPanel.java +++ b/plugins/copyright/src/com/maddyhome/idea/copyright/ui/ProjectSettingsPanel.java @@ -123,7 +123,7 @@ public class ProjectSettingsPanel extends PanelWithButtons { if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { final OptionsEditor optionsEditor = OptionsEditor.KEY.getData(DataManager.getInstance().getDataContext()); if (optionsEditor != null) { - optionsEditor.select(ScopeChooserConfigurable.getInstance(myProject)); + optionsEditor.select(ScopeChooserConfigurable.class); } } } From 07c389646fe5d228d922e8713db971d2f40c4dd3 Mon Sep 17 00:00:00 2001 From: nik Date: Wed, 1 Sep 2010 16:50:44 +0400 Subject: [PATCH 04/15] obsolete method removed --- .../ui/ProjectInspectionToolsConfigurable.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/ProjectInspectionToolsConfigurable.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/ProjectInspectionToolsConfigurable.java index 919e2a5190c2..ef367ad40e19 100644 --- a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/ProjectInspectionToolsConfigurable.java +++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/ProjectInspectionToolsConfigurable.java @@ -22,20 +22,13 @@ package com.intellij.profile.codeInspection.ui; import com.intellij.codeInspection.ex.InspectionProfileImpl; import com.intellij.openapi.options.ConfigurationException; -import com.intellij.openapi.options.ShowSettingsUtil; -import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Comparing; import com.intellij.profile.codeInspection.InspectionProfileManager; import com.intellij.profile.codeInspection.InspectionProjectProfileManager; public class ProjectInspectionToolsConfigurable extends InspectionToolsConfigurable { - public static ProjectInspectionToolsConfigurable getInstance(Project project) { - return ShowSettingsUtil.getInstance().findProjectConfigurable(project, ProjectInspectionToolsConfigurable.class); - } - public ProjectInspectionToolsConfigurable(InspectionProfileManager profileManager, InspectionProjectProfileManager projectProfileManager) { super(projectProfileManager, profileManager); - } protected InspectionProfileImpl getCurrentProfile() { From a57cedec2c0f0e24cee9b2aaf21f8bc1c665f74c Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Wed, 1 Sep 2010 16:50:04 +0400 Subject: [PATCH 05/15] revert unnecessary fix --- .../vcs-impl/src/com/intellij/openapi/vcs/changes/VcsGuess.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/VcsGuess.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/VcsGuess.java index 0fd65ed54031..0c55528aeb8b 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/VcsGuess.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/VcsGuess.java @@ -41,7 +41,7 @@ public class VcsGuess { @Nullable public AbstractVcs getVcsForDirty(final VirtualFile file) { - if (!file.isInLocalFileSystem() || myExcludedFileIndex == null) { + if (!file.isInLocalFileSystem()) { return null; } if (myExcludedFileIndex.isInContent(file) || isFileInBaseDir(file) || From eb6b04d59ae277952d73d0dd45c9f300b5c93dce Mon Sep 17 00:00:00 2001 From: Sergey Evdokimov Date: Wed, 1 Sep 2010 15:14:20 +0400 Subject: [PATCH 06/15] Fix: IDEA-58185 (Grails: Find Usages for variables defined via g:set tag could be added) --- .../statements/expressions/GrReferenceExpressionImpl.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java index 07c6ba82591e..dcfb43c8bbdf 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java @@ -734,10 +734,7 @@ public class GrReferenceExpressionImpl extends GrReferenceElementImpl implements } public boolean isReferenceTo(PsiElement element) { - if (element instanceof PsiNamedElement) { - return getManager().areElementsEquivalent(element, GroovyTargetElementEvaluator.correctSearchTargets(resolve())); - } - return false; + return getManager().areElementsEquivalent(element, GroovyTargetElementEvaluator.correctSearchTargets(resolve())); } @NotNull From ddb761c5379482e0f3cfaff497b6a8d3a15f8884 Mon Sep 17 00:00:00 2001 From: Gregory Shrago Date: Wed, 1 Sep 2010 18:39:27 +0400 Subject: [PATCH 07/15] IDEA-58255 fake extension is useless and ugly --- .../src/com/intellij/execution/console/LanguageConsoleImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java index 7c0f29840789..093cbf98b966 100644 --- a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java @@ -523,7 +523,7 @@ public class LanguageConsoleImpl implements Disposable, TypeSafeDataProvider { } final FileType type = language.getAssociatedFileType(); - @NonNls final String name = getTitle() + "." + (type == null ? "txt" : type.getDefaultExtension()); + @NonNls final String name = getTitle(); final LightVirtualFile newVFile = new LightVirtualFile(name, language, myEditorDocument.getText()); FileDocumentManagerImpl.registerDocument(myEditorDocument, newVFile); myFile = ((PsiFileFactoryImpl)PsiFileFactory.getInstance(myProject)).trySetupPsiForFile(newVFile, language, true, false); From 13ce215164db23ec11c1c2e68a6de6d424d31bfb Mon Sep 17 00:00:00 2001 From: anna Date: Tue, 31 Aug 2010 15:35:21 +0400 Subject: [PATCH 08/15] delegate movers correctly --- .../properties/projectView/ResourceBundleMoveProvider.java | 5 +++++ .../intellij/uiDesigner/projectView/FormMoveProvider.java | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/plugins/properties/src/com/intellij/lang/properties/projectView/ResourceBundleMoveProvider.java b/plugins/properties/src/com/intellij/lang/properties/projectView/ResourceBundleMoveProvider.java index 1ef754cd7522..2794cf0a7abe 100644 --- a/plugins/properties/src/com/intellij/lang/properties/projectView/ResourceBundleMoveProvider.java +++ b/plugins/properties/src/com/intellij/lang/properties/projectView/ResourceBundleMoveProvider.java @@ -21,6 +21,7 @@ import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.diagnostic.Logger; import com.intellij.psi.PsiElement; import com.intellij.refactoring.move.MoveHandlerDelegate; +import org.jetbrains.annotations.Nullable; import java.util.Set; @@ -36,6 +37,10 @@ public class ResourceBundleMoveProvider extends MoveHandlerDelegate { return ResourceBundle.ARRAY_DATA_KEY.getData(dataContext) != null; } + public boolean canMove(PsiElement[] elements, @Nullable final PsiElement targetContainer) { + return false; + } + @Override public void collectFilesOrDirsFromContext(DataContext dataContext, Set filesOrDirs) { diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/projectView/FormMoveProvider.java b/plugins/ui-designer/src/com/intellij/uiDesigner/projectView/FormMoveProvider.java index 12576aade1ab..094a71385902 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/projectView/FormMoveProvider.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/projectView/FormMoveProvider.java @@ -22,6 +22,7 @@ import com.intellij.psi.PsiClass; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.refactoring.move.MoveHandlerDelegate; +import org.jetbrains.annotations.Nullable; import java.util.Set; @@ -37,6 +38,10 @@ public class FormMoveProvider extends MoveHandlerDelegate { return forms != null && forms.length > 0; } + public boolean canMove(PsiElement[] elements, @Nullable final PsiElement targetContainer) { + return false; + } + @Override public void collectFilesOrDirsFromContext(DataContext dataContext, Set filesOrDirs) { Form[] forms = Form.DATA_KEY.getData(dataContext); From d1a1ac985d0ac77d621588f0aa7101209df1e57e Mon Sep 17 00:00:00 2001 From: anna Date: Tue, 31 Aug 2010 20:10:06 +0400 Subject: [PATCH 09/15] move: do not move all file classes if only one was selected in presence of non-java file (IDEA-57353) --- .../JavaMoveFilesOrDirectoriesHandler.java | 78 ++++++++++++++++- .../allClassesInFile/after/s/empty.txt | 0 .../allClassesInFile/after/t/MyClass.java | 5 ++ .../allClassesInFile/after/t/empty.txt | 0 .../allClassesInFile/after/t/txt2move.txt | 0 .../allClassesInFile/before/s/MyClass.java | 3 + .../allClassesInFile/before/s/empty.txt | 0 .../allClassesInFile/before/s/txt2move.txt | 0 .../allClassesInFile/before/t/empty.txt | 0 .../after/s/MyLocal.java | 3 + .../leavePackageLocalClass/after/s/empty.txt | 0 .../after/t/MyClass.java | 2 + .../leavePackageLocalClass/after/t/empty.txt | 0 .../after/t/txt2move.txt | 0 .../before/s/MyClass.java | 3 + .../leavePackageLocalClass/before/s/empty.txt | 0 .../before/s/txt2move.txt | 0 .../leavePackageLocalClass/before/t/empty.txt | 0 .../after/s/MyClass.java | 2 + .../onlyPackageLocalClass/after/s/empty.txt | 0 .../after/t/MyLocal.java | 3 + .../onlyPackageLocalClass/after/t/empty.txt | 0 .../after/t/txt2move.txt | 0 .../before/s/MyClass.java | 3 + .../onlyPackageLocalClass/before/s/empty.txt | 0 .../before/s/txt2move.txt | 0 .../onlyPackageLocalClass/before/t/empty.txt | 0 .../refactoring/MoveClassAndFileTest.java | 86 +++++++++++++++++++ .../MoveFilesOrDirectoriesUtil.java | 42 ++++++--- 29 files changed, 216 insertions(+), 14 deletions(-) create mode 100644 java/java-tests/testData/refactoring/moveClassAndFile/allClassesInFile/after/s/empty.txt create mode 100644 java/java-tests/testData/refactoring/moveClassAndFile/allClassesInFile/after/t/MyClass.java create mode 100644 java/java-tests/testData/refactoring/moveClassAndFile/allClassesInFile/after/t/empty.txt create mode 100644 java/java-tests/testData/refactoring/moveClassAndFile/allClassesInFile/after/t/txt2move.txt create mode 100644 java/java-tests/testData/refactoring/moveClassAndFile/allClassesInFile/before/s/MyClass.java create mode 100644 java/java-tests/testData/refactoring/moveClassAndFile/allClassesInFile/before/s/empty.txt create mode 100644 java/java-tests/testData/refactoring/moveClassAndFile/allClassesInFile/before/s/txt2move.txt create mode 100644 java/java-tests/testData/refactoring/moveClassAndFile/allClassesInFile/before/t/empty.txt create mode 100644 java/java-tests/testData/refactoring/moveClassAndFile/leavePackageLocalClass/after/s/MyLocal.java create mode 100644 java/java-tests/testData/refactoring/moveClassAndFile/leavePackageLocalClass/after/s/empty.txt create mode 100644 java/java-tests/testData/refactoring/moveClassAndFile/leavePackageLocalClass/after/t/MyClass.java create mode 100644 java/java-tests/testData/refactoring/moveClassAndFile/leavePackageLocalClass/after/t/empty.txt create mode 100644 java/java-tests/testData/refactoring/moveClassAndFile/leavePackageLocalClass/after/t/txt2move.txt create mode 100644 java/java-tests/testData/refactoring/moveClassAndFile/leavePackageLocalClass/before/s/MyClass.java create mode 100644 java/java-tests/testData/refactoring/moveClassAndFile/leavePackageLocalClass/before/s/empty.txt create mode 100644 java/java-tests/testData/refactoring/moveClassAndFile/leavePackageLocalClass/before/s/txt2move.txt create mode 100644 java/java-tests/testData/refactoring/moveClassAndFile/leavePackageLocalClass/before/t/empty.txt create mode 100644 java/java-tests/testData/refactoring/moveClassAndFile/onlyPackageLocalClass/after/s/MyClass.java create mode 100644 java/java-tests/testData/refactoring/moveClassAndFile/onlyPackageLocalClass/after/s/empty.txt create mode 100644 java/java-tests/testData/refactoring/moveClassAndFile/onlyPackageLocalClass/after/t/MyLocal.java create mode 100644 java/java-tests/testData/refactoring/moveClassAndFile/onlyPackageLocalClass/after/t/empty.txt create mode 100644 java/java-tests/testData/refactoring/moveClassAndFile/onlyPackageLocalClass/after/t/txt2move.txt create mode 100644 java/java-tests/testData/refactoring/moveClassAndFile/onlyPackageLocalClass/before/s/MyClass.java create mode 100644 java/java-tests/testData/refactoring/moveClassAndFile/onlyPackageLocalClass/before/s/empty.txt create mode 100644 java/java-tests/testData/refactoring/moveClassAndFile/onlyPackageLocalClass/before/s/txt2move.txt create mode 100644 java/java-tests/testData/refactoring/moveClassAndFile/onlyPackageLocalClass/before/t/empty.txt create mode 100644 java/java-tests/testSrc/com/intellij/refactoring/MoveClassAndFileTest.java diff --git a/java/java-impl/src/com/intellij/refactoring/move/moveFilesOrDirectories/JavaMoveFilesOrDirectoriesHandler.java b/java/java-impl/src/com/intellij/refactoring/move/moveFilesOrDirectories/JavaMoveFilesOrDirectoriesHandler.java index f56925dfded3..37ff8d3d3b5e 100644 --- a/java/java-impl/src/com/intellij/refactoring/move/moveFilesOrDirectories/JavaMoveFilesOrDirectoriesHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/move/moveFilesOrDirectories/JavaMoveFilesOrDirectoriesHandler.java @@ -15,11 +15,20 @@ */ package com.intellij.refactoring.move.moveFilesOrDirectories; +import com.intellij.codeInsight.daemon.impl.CollectHighlightsUtil; +import com.intellij.openapi.application.Result; +import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.project.Project; import com.intellij.psi.*; +import com.intellij.psi.impl.file.JavaDirectoryServiceImpl; import com.intellij.refactoring.copy.JavaCopyFilesOrDirectoriesHandler; import com.intellij.refactoring.move.MoveCallback; -import com.intellij.codeInsight.daemon.impl.CollectHighlightsUtil; +import com.intellij.util.ArrayUtil; +import com.intellij.util.Function; +import com.intellij.util.IncorrectOperationException; +import org.jetbrains.annotations.Nullable; + +import java.util.*; public class JavaMoveFilesOrDirectoriesHandler extends MoveFilesOrDirectoriesHandler { @Override @@ -55,7 +64,70 @@ public class JavaMoveFilesOrDirectoriesHandler extends MoveFilesOrDirectoriesHan } @Override - public void doMove(Project project, PsiElement[] elements, PsiElement targetContainer, MoveCallback callback) { - super.doMove(project, elements, targetContainer, callback); + public void doMove(final Project project, PsiElement[] elements, PsiElement targetContainer, MoveCallback callback) { + + MoveFilesOrDirectoriesUtil + .doMove(project, elements, new PsiElement[]{targetContainer}, callback, new Function() { + @Override + public PsiElement[] fun(final PsiElement[] elements) { + return new WriteCommandAction(project, "Regrouping ...") { + @Override + protected void run(Result result) throws Throwable { + final List adjustedElements = new ArrayList(); + for (PsiElement element : elements) { + if (element instanceof PsiClass) { + final PsiFile containingFile = obtainContainingFile(element, elements); + if (containingFile != null && !adjustedElements.contains(containingFile)) { + adjustedElements.add(containingFile); + } + } + else { + adjustedElements.add(element); + } + } + result.setResult(adjustedElements.toArray(new PsiElement[adjustedElements.size()])); + } + }.execute().getResultObject(); + } + }); + } + + @Nullable + private static PsiFile obtainContainingFile(PsiElement element, PsiElement[] elements) { + final PsiClass[] classes = ((PsiClassOwner)element.getParent()).getClasses(); + final Set nonMovedClasses = new HashSet(); + for (PsiClass aClass : classes) { + if (ArrayUtil.find(elements, aClass) < 0) { + nonMovedClasses.add(aClass); + } + } + final PsiFile containingFile = element.getContainingFile(); + if (nonMovedClasses.isEmpty()) { + return containingFile; + } + else { + final PsiDirectory containingDirectory = containingFile.getContainingDirectory(); + if (containingDirectory != null) { + try { + JavaDirectoryServiceImpl.checkCreateClassOrInterface(containingDirectory, ((PsiClass)element).getName()); + final PsiElement createdClass = containingDirectory.add(element); + element.delete(); + return createdClass.getContainingFile(); + } + catch (IncorrectOperationException e) { + final Iterator iterator = nonMovedClasses.iterator(); + final PsiClass nonMovedClass = iterator.next(); + final PsiElement createdFile = containingDirectory.add(nonMovedClass).getContainingFile(); + nonMovedClass.delete(); + while (iterator.hasNext()) { + final PsiClass currentClass = iterator.next(); + createdFile.add(currentClass); + currentClass.delete(); + } + return containingFile; + } + } + } + return null; } } diff --git a/java/java-tests/testData/refactoring/moveClassAndFile/allClassesInFile/after/s/empty.txt b/java/java-tests/testData/refactoring/moveClassAndFile/allClassesInFile/after/s/empty.txt new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/java/java-tests/testData/refactoring/moveClassAndFile/allClassesInFile/after/t/MyClass.java b/java/java-tests/testData/refactoring/moveClassAndFile/allClassesInFile/after/t/MyClass.java new file mode 100644 index 000000000000..0823aa058000 --- /dev/null +++ b/java/java-tests/testData/refactoring/moveClassAndFile/allClassesInFile/after/t/MyClass.java @@ -0,0 +1,5 @@ +package t; + +class MyClass{} + +class MyOneMoreClass{} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/moveClassAndFile/allClassesInFile/after/t/empty.txt b/java/java-tests/testData/refactoring/moveClassAndFile/allClassesInFile/after/t/empty.txt new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/java/java-tests/testData/refactoring/moveClassAndFile/allClassesInFile/after/t/txt2move.txt b/java/java-tests/testData/refactoring/moveClassAndFile/allClassesInFile/after/t/txt2move.txt new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/java/java-tests/testData/refactoring/moveClassAndFile/allClassesInFile/before/s/MyClass.java b/java/java-tests/testData/refactoring/moveClassAndFile/allClassesInFile/before/s/MyClass.java new file mode 100644 index 000000000000..222b6d287d5c --- /dev/null +++ b/java/java-tests/testData/refactoring/moveClassAndFile/allClassesInFile/before/s/MyClass.java @@ -0,0 +1,3 @@ +package s; +class MyClass{} +class MyOneMoreClass{} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/moveClassAndFile/allClassesInFile/before/s/empty.txt b/java/java-tests/testData/refactoring/moveClassAndFile/allClassesInFile/before/s/empty.txt new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/java/java-tests/testData/refactoring/moveClassAndFile/allClassesInFile/before/s/txt2move.txt b/java/java-tests/testData/refactoring/moveClassAndFile/allClassesInFile/before/s/txt2move.txt new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/java/java-tests/testData/refactoring/moveClassAndFile/allClassesInFile/before/t/empty.txt b/java/java-tests/testData/refactoring/moveClassAndFile/allClassesInFile/before/t/empty.txt new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/java/java-tests/testData/refactoring/moveClassAndFile/leavePackageLocalClass/after/s/MyLocal.java b/java/java-tests/testData/refactoring/moveClassAndFile/leavePackageLocalClass/after/s/MyLocal.java new file mode 100644 index 000000000000..2f4a3c18c169 --- /dev/null +++ b/java/java-tests/testData/refactoring/moveClassAndFile/leavePackageLocalClass/after/s/MyLocal.java @@ -0,0 +1,3 @@ +package s; + +class MyLocal{} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/moveClassAndFile/leavePackageLocalClass/after/s/empty.txt b/java/java-tests/testData/refactoring/moveClassAndFile/leavePackageLocalClass/after/s/empty.txt new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/java/java-tests/testData/refactoring/moveClassAndFile/leavePackageLocalClass/after/t/MyClass.java b/java/java-tests/testData/refactoring/moveClassAndFile/leavePackageLocalClass/after/t/MyClass.java new file mode 100644 index 000000000000..c6cc48aee88f --- /dev/null +++ b/java/java-tests/testData/refactoring/moveClassAndFile/leavePackageLocalClass/after/t/MyClass.java @@ -0,0 +1,2 @@ +package t; +public class MyClass{} diff --git a/java/java-tests/testData/refactoring/moveClassAndFile/leavePackageLocalClass/after/t/empty.txt b/java/java-tests/testData/refactoring/moveClassAndFile/leavePackageLocalClass/after/t/empty.txt new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/java/java-tests/testData/refactoring/moveClassAndFile/leavePackageLocalClass/after/t/txt2move.txt b/java/java-tests/testData/refactoring/moveClassAndFile/leavePackageLocalClass/after/t/txt2move.txt new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/java/java-tests/testData/refactoring/moveClassAndFile/leavePackageLocalClass/before/s/MyClass.java b/java/java-tests/testData/refactoring/moveClassAndFile/leavePackageLocalClass/before/s/MyClass.java new file mode 100644 index 000000000000..04f95fadb223 --- /dev/null +++ b/java/java-tests/testData/refactoring/moveClassAndFile/leavePackageLocalClass/before/s/MyClass.java @@ -0,0 +1,3 @@ +package s; +public class MyClass{} +class MyLocal{} diff --git a/java/java-tests/testData/refactoring/moveClassAndFile/leavePackageLocalClass/before/s/empty.txt b/java/java-tests/testData/refactoring/moveClassAndFile/leavePackageLocalClass/before/s/empty.txt new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/java/java-tests/testData/refactoring/moveClassAndFile/leavePackageLocalClass/before/s/txt2move.txt b/java/java-tests/testData/refactoring/moveClassAndFile/leavePackageLocalClass/before/s/txt2move.txt new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/java/java-tests/testData/refactoring/moveClassAndFile/leavePackageLocalClass/before/t/empty.txt b/java/java-tests/testData/refactoring/moveClassAndFile/leavePackageLocalClass/before/t/empty.txt new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/java/java-tests/testData/refactoring/moveClassAndFile/onlyPackageLocalClass/after/s/MyClass.java b/java/java-tests/testData/refactoring/moveClassAndFile/onlyPackageLocalClass/after/s/MyClass.java new file mode 100644 index 000000000000..5bcead3536b5 --- /dev/null +++ b/java/java-tests/testData/refactoring/moveClassAndFile/onlyPackageLocalClass/after/s/MyClass.java @@ -0,0 +1,2 @@ +package s; +public class MyClass{} diff --git a/java/java-tests/testData/refactoring/moveClassAndFile/onlyPackageLocalClass/after/s/empty.txt b/java/java-tests/testData/refactoring/moveClassAndFile/onlyPackageLocalClass/after/s/empty.txt new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/java/java-tests/testData/refactoring/moveClassAndFile/onlyPackageLocalClass/after/t/MyLocal.java b/java/java-tests/testData/refactoring/moveClassAndFile/onlyPackageLocalClass/after/t/MyLocal.java new file mode 100644 index 000000000000..91dd34d799e6 --- /dev/null +++ b/java/java-tests/testData/refactoring/moveClassAndFile/onlyPackageLocalClass/after/t/MyLocal.java @@ -0,0 +1,3 @@ +package t; + +class MyLocal{} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/moveClassAndFile/onlyPackageLocalClass/after/t/empty.txt b/java/java-tests/testData/refactoring/moveClassAndFile/onlyPackageLocalClass/after/t/empty.txt new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/java/java-tests/testData/refactoring/moveClassAndFile/onlyPackageLocalClass/after/t/txt2move.txt b/java/java-tests/testData/refactoring/moveClassAndFile/onlyPackageLocalClass/after/t/txt2move.txt new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/java/java-tests/testData/refactoring/moveClassAndFile/onlyPackageLocalClass/before/s/MyClass.java b/java/java-tests/testData/refactoring/moveClassAndFile/onlyPackageLocalClass/before/s/MyClass.java new file mode 100644 index 000000000000..04f95fadb223 --- /dev/null +++ b/java/java-tests/testData/refactoring/moveClassAndFile/onlyPackageLocalClass/before/s/MyClass.java @@ -0,0 +1,3 @@ +package s; +public class MyClass{} +class MyLocal{} diff --git a/java/java-tests/testData/refactoring/moveClassAndFile/onlyPackageLocalClass/before/s/empty.txt b/java/java-tests/testData/refactoring/moveClassAndFile/onlyPackageLocalClass/before/s/empty.txt new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/java/java-tests/testData/refactoring/moveClassAndFile/onlyPackageLocalClass/before/s/txt2move.txt b/java/java-tests/testData/refactoring/moveClassAndFile/onlyPackageLocalClass/before/s/txt2move.txt new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/java/java-tests/testData/refactoring/moveClassAndFile/onlyPackageLocalClass/before/t/empty.txt b/java/java-tests/testData/refactoring/moveClassAndFile/onlyPackageLocalClass/before/t/empty.txt new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/java/java-tests/testSrc/com/intellij/refactoring/MoveClassAndFileTest.java b/java/java-tests/testSrc/com/intellij/refactoring/MoveClassAndFileTest.java new file mode 100644 index 000000000000..b9a1d2d65db9 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/refactoring/MoveClassAndFileTest.java @@ -0,0 +1,86 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.refactoring; + +/** + * User: anna + * Date: Aug 31, 2010 + */ + +import com.intellij.JavaTestUtil; +import com.intellij.codeInsight.CodeInsightTestCase; +import com.intellij.openapi.fileEditor.FileDocumentManager; +import com.intellij.openapi.projectRoots.impl.JavaSdkImpl; +import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.*; +import com.intellij.psi.impl.source.PostprocessReformattingAspect; +import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.refactoring.move.moveFilesOrDirectories.JavaMoveFilesOrDirectoriesHandler; +import com.intellij.testFramework.IdeaTestUtil; +import com.intellij.testFramework.PsiTestUtil; + +import java.io.File; + +public class MoveClassAndFileTest extends CodeInsightTestCase { + + public void testAllClassesInFile() throws Exception { + doTest("allClassesInFile", "t", "txt2move.txt", "s.MyClass", "s.MyOneMoreClass"); + } + + public void testOnlyPackageLocalClass() throws Exception { + doTest("onlyPackageLocalClass", "t", "txt2move.txt", "s.MyLocal"); + } + + public void testLeavePackageLocalClass() throws Exception { + doTest("leavePackageLocalClass", "t", "txt2move.txt", "s.MyClass"); + } + + private void doTest(String testName, String newPackageName, String fileNameNearFirstClass, String... classNames) throws Exception { + String root = JavaTestUtil.getJavaTestDataPath() + "/refactoring/moveClassAndFile/" + testName; + + String rootBefore = root + "/before"; + PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17()); + VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete); + + performAction(newPackageName, fileNameNearFirstClass, classNames); + + String rootAfter = root + "/after"; + VirtualFile rootDir2 = LocalFileSystem.getInstance().findFileByPath(rootAfter.replace(File.separatorChar, '/')); + myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting(); + IdeaTestUtil.assertDirectoriesEqual(rootDir2, rootDir, IdeaTestUtil.CVS_FILE_FILTER); + } + + private void performAction(String newPackageName, String fileName, String... classNames) throws Exception{ + final PsiElement[] elements = new PsiElement[classNames.length + 1]; + for(int i = 0; i < classNames.length; i++){ + String className = classNames[i]; + elements[i] = myJavaFacade.findClass(className, GlobalSearchScope.projectScope(getProject())); + assertNotNull("Class " + className + " not found", elements[i]); + } + elements[classNames.length] = elements[0].getContainingFile().getContainingDirectory().findFile(fileName); + + PsiPackage aPackage = JavaPsiFacade.getInstance(myPsiManager.getProject()).findPackage(newPackageName); + assertNotNull("Package " + newPackageName + " not found", aPackage); + final PsiDirectory[] dirs = aPackage.getDirectories(); + assertEquals(dirs.length, 1); + + new JavaMoveFilesOrDirectoriesHandler().doMove(getProject(), elements, dirs[0], null); + PsiDocumentManager.getInstance(myProject).commitAllDocuments(); + FileDocumentManager.getInstance().saveAllDocuments(); + } +} + diff --git a/platform/lang-impl/src/com/intellij/refactoring/move/moveFilesOrDirectories/MoveFilesOrDirectoriesUtil.java b/platform/lang-impl/src/com/intellij/refactoring/move/moveFilesOrDirectories/MoveFilesOrDirectoriesUtil.java index 3153b7e58dce..ee871bc75896 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/move/moveFilesOrDirectories/MoveFilesOrDirectoriesUtil.java +++ b/platform/lang-impl/src/com/intellij/refactoring/move/moveFilesOrDirectories/MoveFilesOrDirectoriesUtil.java @@ -17,6 +17,7 @@ package com.intellij.refactoring.move.moveFilesOrDirectories; import com.intellij.ide.util.DirectoryChooserUtil; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; @@ -24,6 +25,7 @@ import com.intellij.psi.*; import com.intellij.refactoring.RefactoringBundle; import com.intellij.refactoring.move.MoveCallback; import com.intellij.refactoring.util.CommonRefactoringUtil; +import com.intellij.util.Function; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.Nullable; @@ -59,9 +61,22 @@ public class MoveFilesOrDirectoriesUtil { final PsiElement[] elements, final PsiElement[] targetElement, final MoveCallback moveCallback) { - for (PsiElement element : elements) { - if (!(element instanceof PsiFile) && !(element instanceof PsiDirectory)) { - throw new IllegalArgumentException("unexpected element type: " + element); + doMove(project, elements, targetElement, moveCallback, null); + } + + /** + * @param elements should contain PsiDirectories or PsiFiles only if adjustElements == null + */ + public static void doMove(final Project project, + final PsiElement[] elements, + final PsiElement[] targetElement, + final MoveCallback moveCallback, + final Function adjustElements) { + if (adjustElements == null) { + for (PsiElement element : elements) { + if (!(element instanceof PsiFile) && !(element instanceof PsiDirectory)) { + throw new IllegalArgumentException("unexpected element type: " + element); + } } } @@ -72,21 +87,21 @@ public class MoveFilesOrDirectoriesUtil { final MoveFilesOrDirectoriesDialog.Callback doRun = new MoveFilesOrDirectoriesDialog.Callback() { public void run(final MoveFilesOrDirectoriesDialog moveDialog) { - final PsiDirectory targetDirectory = moveDialog.getTargetDirectory(); + final PsiDirectory targetDirectory = moveDialog != null ? moveDialog.getTargetDirectory() : initialTargetDirectory; LOG.assertTrue(targetDirectory != null); - + PsiElement[] newElements = adjustElements != null ? adjustElements.fun(elements) : elements; targetElement[0] = targetDirectory; PsiManager manager = PsiManager.getInstance(project); try { - for (PsiElement psiElement : elements) { + for (PsiElement psiElement : newElements) { manager.checkMove(psiElement, targetDirectory); } - new MoveFilesOrDirectoriesProcessor(project, elements, targetDirectory, false, false, moveCallback, new Runnable() { + new MoveFilesOrDirectoriesProcessor(project, newElements, targetDirectory, false, false, moveCallback, new Runnable() { public void run() { - moveDialog.close(DialogWrapper.CANCEL_EXIT_CODE); + if (moveDialog != null) moveDialog.close(DialogWrapper.CANCEL_EXIT_CODE); } }).run(); } @@ -97,9 +112,14 @@ public class MoveFilesOrDirectoriesUtil { } }; - final MoveFilesOrDirectoriesDialog moveDialog = new MoveFilesOrDirectoriesDialog(project, doRun); - moveDialog.setData(elements, initialTargetDirectory, "refactoring.moveFile"); - moveDialog.show(); + if (ApplicationManager.getApplication().isUnitTestMode()) { + doRun.run(null); + } + else { + final MoveFilesOrDirectoriesDialog moveDialog = new MoveFilesOrDirectoriesDialog(project, doRun); + moveDialog.setData(elements, initialTargetDirectory, "refactoring.moveFile"); + moveDialog.show(); + } } @Nullable From 1d5890916371323d631e0fd460003b9d9d021304 Mon Sep 17 00:00:00 2001 From: anna Date: Tue, 31 Aug 2010 20:39:26 +0400 Subject: [PATCH 10/15] move: api to check if move via DnD is actually redundant (IDEA-57366 ;IDEA-57365 ) --- .../MoveClassesOrPackagesHandlerBase.java | 15 +++++++++++++++ .../projectView/impl/MoveDropTargetListener.java | 3 +-- .../intellij/refactoring/move/MoveHandler.java | 7 +++++++ .../refactoring/move/MoveHandlerDelegate.java | 4 ++++ .../projectView/ResourceBundleMoveProvider.java | 10 ++++++++++ .../uiDesigner/projectView/FormMoveProvider.java | 13 +++++++++++++ 6 files changed, 50 insertions(+), 2 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveClassesOrPackagesHandlerBase.java b/java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveClassesOrPackagesHandlerBase.java index 15dded63dda6..bec9ae48471c 100644 --- a/java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveClassesOrPackagesHandlerBase.java +++ b/java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveClassesOrPackagesHandlerBase.java @@ -24,6 +24,7 @@ import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; +import com.intellij.psi.impl.file.JavaDirectoryServiceImpl; import com.intellij.psi.impl.source.jsp.jspJava.JspClass; import com.intellij.refactoring.JavaRefactoringSettings; import com.intellij.refactoring.RefactoringBundle; @@ -33,6 +34,7 @@ import com.intellij.refactoring.util.CommonRefactoringUtil; import com.intellij.openapi.project.Project; import com.intellij.refactoring.util.RadioUpDownListener; import com.intellij.refactoring.util.RefactoringUtil; +import com.intellij.util.IncorrectOperationException; import com.intellij.util.containers.HashSet; import org.jetbrains.annotations.Nullable; @@ -294,4 +296,17 @@ public class MoveClassesOrPackagesHandlerBase extends MoveHandlerDelegate { } return false; } + + @Override + public boolean isMoveRedundant(PsiElement source, PsiElement target) { + if (target instanceof PsiDirectory && source instanceof PsiClass) { + try { + JavaDirectoryServiceImpl.checkCreateClassOrInterface((PsiDirectory)target, ((PsiClass)source).getName()); + } + catch (IncorrectOperationException e) { + return true; + } + } + return super.isMoveRedundant(source, target); + } } diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/MoveDropTargetListener.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/MoveDropTargetListener.java index 59067ae96c61..4fb424ff8a3b 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/MoveDropTargetListener.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/MoveDropTargetListener.java @@ -27,7 +27,6 @@ import com.intellij.psi.*; import com.intellij.refactoring.RefactoringActionHandler; import com.intellij.refactoring.RefactoringActionHandlerFactory; import com.intellij.refactoring.actions.BaseRefactoringAction; -import com.intellij.refactoring.actions.MoveAction; import com.intellij.refactoring.copy.CopyHandler; import com.intellij.refactoring.move.MoveHandler; import org.jetbrains.annotations.NonNls; @@ -326,7 +325,7 @@ class MoveDropTargetListener implements DropTargetListener { } public boolean isDropRedundant(@NotNull TreeNode sourceNode, @NotNull TreeNode targetNode) { - return sourceNode.getParent() == targetNode; + return sourceNode.getParent() == targetNode || MoveHandler.isMoveRedundant(getPsiElement(sourceNode), getPsiElement(targetNode)); } public boolean shouldDelegateToParent(TreeNode[] sourceNodes, @NotNull final TreeNode targetNode) { diff --git a/platform/lang-impl/src/com/intellij/refactoring/move/MoveHandler.java b/platform/lang-impl/src/com/intellij/refactoring/move/MoveHandler.java index 25aa9cc90021..af154a3bc4b6 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/move/MoveHandler.java +++ b/platform/lang-impl/src/com/intellij/refactoring/move/MoveHandler.java @@ -173,4 +173,11 @@ public class MoveHandler implements RefactoringActionHandler { return false; } + + public static boolean isMoveRedundant(PsiElement source, PsiElement target) { + for(MoveHandlerDelegate delegate: Extensions.getExtensions(MoveHandlerDelegate.EP_NAME)) { + if (delegate.isMoveRedundant(source, target)) return true; + } + return false; + } } diff --git a/platform/lang-impl/src/com/intellij/refactoring/move/MoveHandlerDelegate.java b/platform/lang-impl/src/com/intellij/refactoring/move/MoveHandlerDelegate.java index bfa33fd98b3a..7181e2ae5863 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/move/MoveHandlerDelegate.java +++ b/platform/lang-impl/src/com/intellij/refactoring/move/MoveHandlerDelegate.java @@ -60,4 +60,8 @@ public abstract class MoveHandlerDelegate { public void collectFilesOrDirsFromContext(DataContext dataContext, Set filesOrDirs){ } + + public boolean isMoveRedundant(PsiElement source, PsiElement target) { + return false; + } } diff --git a/plugins/properties/src/com/intellij/lang/properties/projectView/ResourceBundleMoveProvider.java b/plugins/properties/src/com/intellij/lang/properties/projectView/ResourceBundleMoveProvider.java index 2794cf0a7abe..15aee3cb1b17 100644 --- a/plugins/properties/src/com/intellij/lang/properties/projectView/ResourceBundleMoveProvider.java +++ b/plugins/properties/src/com/intellij/lang/properties/projectView/ResourceBundleMoveProvider.java @@ -16,9 +16,11 @@ package com.intellij.lang.properties.projectView; import com.intellij.lang.properties.ResourceBundle; +import com.intellij.lang.properties.psi.PropertiesFile; import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.psi.PsiDirectory; import com.intellij.psi.PsiElement; import com.intellij.refactoring.move.MoveHandlerDelegate; import org.jetbrains.annotations.Nullable; @@ -50,4 +52,12 @@ public class ResourceBundleMoveProvider extends MoveHandlerDelegate { filesOrDirs.addAll(bundle.getPropertiesFiles(PlatformDataKeys.PROJECT.getData(dataContext))); } } + + @Override + public boolean isMoveRedundant(PsiElement source, PsiElement target) { + if (source instanceof PropertiesFile && target instanceof PsiDirectory) { + return source.getParent() == target; + } + return super.isMoveRedundant(source, target); + } } diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/projectView/FormMoveProvider.java b/plugins/ui-designer/src/com/intellij/uiDesigner/projectView/FormMoveProvider.java index 094a71385902..a94456da68d5 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/projectView/FormMoveProvider.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/projectView/FormMoveProvider.java @@ -18,10 +18,12 @@ package com.intellij.uiDesigner.projectView; import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.refactoring.move.MoveHandlerDelegate; +import com.intellij.uiDesigner.GuiFormFileType; import org.jetbrains.annotations.Nullable; import java.util.Set; @@ -60,4 +62,15 @@ public class FormMoveProvider extends MoveHandlerDelegate { } } + + @Override + public boolean isMoveRedundant(PsiElement source, PsiElement target) { + if (source instanceof PsiFile && source.getParent() == target) { + final VirtualFile virtualFile = ((PsiFile)source).getVirtualFile(); + if (virtualFile != null && virtualFile.getFileType() instanceof GuiFormFileType) { + return true; + } + } + return super.isMoveRedundant(source, target); + } } From 30df6ff4dc9e50d52baf421525ef3e17573f6f2a Mon Sep 17 00:00:00 2001 From: anna Date: Tue, 31 Aug 2010 21:06:54 +0400 Subject: [PATCH 11/15] move: check if dnd move is disabled --- .../dndMove/publicJavaClass/d/MyClass.java | 2 + .../dndMove/secondJavaClass/d/MyClass.java | 5 ++ .../com/intellij/refactoring/DndMoveTest.java | 52 +++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 java/java-tests/testData/refactoring/dndMove/publicJavaClass/d/MyClass.java create mode 100644 java/java-tests/testData/refactoring/dndMove/secondJavaClass/d/MyClass.java create mode 100644 java/java-tests/testSrc/com/intellij/refactoring/DndMoveTest.java diff --git a/java/java-tests/testData/refactoring/dndMove/publicJavaClass/d/MyClass.java b/java/java-tests/testData/refactoring/dndMove/publicJavaClass/d/MyClass.java new file mode 100644 index 000000000000..90f42c3eaaa1 --- /dev/null +++ b/java/java-tests/testData/refactoring/dndMove/publicJavaClass/d/MyClass.java @@ -0,0 +1,2 @@ +package d; +public class MyClass{} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/dndMove/secondJavaClass/d/MyClass.java b/java/java-tests/testData/refactoring/dndMove/secondJavaClass/d/MyClass.java new file mode 100644 index 000000000000..78ad73a1706e --- /dev/null +++ b/java/java-tests/testData/refactoring/dndMove/secondJavaClass/d/MyClass.java @@ -0,0 +1,5 @@ +package d; + +public class MyClass{} + +class Second{} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/refactoring/DndMoveTest.java b/java/java-tests/testSrc/com/intellij/refactoring/DndMoveTest.java new file mode 100644 index 000000000000..b0c487496649 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/refactoring/DndMoveTest.java @@ -0,0 +1,52 @@ +package com.intellij.refactoring; + +import com.intellij.codeInsight.CodeInsightTestCase; +import com.intellij.openapi.util.Computable; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.*; +import com.intellij.refactoring.move.MoveHandler; +import com.intellij.testFramework.PsiTestUtil; +import org.jetbrains.annotations.Nullable; + +/** + * User: anna + * Date: Aug 31, 2010 + */ +public class DndMoveTest extends CodeInsightTestCase { + protected String getTestRoot() { + return "/refactoring/dndMove/"; + } + + public void testPublicJavaClass() throws Exception { + doTest("d", new Computable() { + @Nullable + @Override + public PsiElement compute() { + return JavaPsiFacade.getInstance(getProject()).findClass("d.MyClass"); + } + }, true); + } + + public void testSecondJavaClass() throws Exception { + doTest("d", new Computable() { + @Nullable + @Override + public PsiElement compute() { + return JavaPsiFacade.getInstance(getProject()).findClass("d.Second"); + } + }, false); + } + + + private void doTest(final String targetDirName, final Computable source, final boolean expected) throws Exception { + String testName = getTestName(true); + String root = getTestDataPath() + getTestRoot() + testName; + VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete, false); + PsiTestUtil.addSourceContentToRoots(myModule, rootDir); + PsiDocumentManager.getInstance(myProject).commitAllDocuments(); + final VirtualFile child1 = rootDir.findChild(targetDirName); + assertNotNull("File " + targetDirName + " not found", child1); + final PsiDirectory targetDirectory = myPsiManager.findDirectory(child1); + assertEquals(expected, MoveHandler.isMoveRedundant(source.compute(), targetDirectory)); + } +} \ No newline at end of file From 70756f060ab8b74827fae9221a6f3b0bb429d7c3 Mon Sep 17 00:00:00 2001 From: anna Date: Wed, 1 Sep 2010 12:50:03 +0400 Subject: [PATCH 12/15] testng should show log console in debug if configured (IDEA-58165) --- .../execution/configurations/RunConfigurationBase.java | 4 ---- .../intellij/xdebugger/impl/ui/DebuggerSessionTabBase.java | 2 +- .../testng/configuration/TestNGConfiguration.java | 4 ---- 3 files changed, 1 insertion(+), 9 deletions(-) diff --git a/platform/lang-api/src/com/intellij/execution/configurations/RunConfigurationBase.java b/platform/lang-api/src/com/intellij/execution/configurations/RunConfigurationBase.java index 6628bd2934ad..6bc96b85e060 100644 --- a/platform/lang-api/src/com/intellij/execution/configurations/RunConfigurationBase.java +++ b/platform/lang-api/src/com/intellij/execution/configurations/RunConfigurationBase.java @@ -182,8 +182,4 @@ public abstract class RunConfigurationBase extends UserDataHolderBase implements } } - public boolean needAdditionalConsole() { - return true; - } - } diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerSessionTabBase.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerSessionTabBase.java index 7100705fd3d6..fa346c0359d0 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerSessionTabBase.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerSessionTabBase.java @@ -82,7 +82,7 @@ public abstract class DebuggerSessionTabBase implements DebuggerLogConsoleManage } protected void initLogConsoles(final RunProfile runConfiguration, final ProcessHandler processHandler) { - if (runConfiguration instanceof RunConfigurationBase && ((RunConfigurationBase)runConfiguration).needAdditionalConsole()) { + if (runConfiguration instanceof RunConfigurationBase) { myManager.initLogConsoles((RunConfigurationBase)runConfiguration, processHandler); } } diff --git a/plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGConfiguration.java b/plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGConfiguration.java index dfb93f683d3f..3a0652e355fc 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGConfiguration.java +++ b/plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGConfiguration.java @@ -266,10 +266,6 @@ public class TestNGConfiguration extends ModuleBasedConfiguration Date: Wed, 1 Sep 2010 13:51:34 +0400 Subject: [PATCH 13/15] @NotNulls --- .../intellij/execution/testframework/AbstractTestProxy.java | 5 +++-- .../intellij/execution/testframework/CompositePrintable.java | 5 +++-- .../intellij/execution/testframework/DeferingPrinter.java | 3 ++- .../src/com/intellij/execution/testframework/Printer.java | 3 ++- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/platform/testRunner/src/com/intellij/execution/testframework/AbstractTestProxy.java b/platform/testRunner/src/com/intellij/execution/testframework/AbstractTestProxy.java index 72e1d096fab7..da8b76097512 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/AbstractTestProxy.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/AbstractTestProxy.java @@ -25,6 +25,7 @@ import com.intellij.openapi.actionSystem.DataKey; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Disposer; import com.intellij.pom.Navigatable; +import org.jetbrains.annotations.NotNull; import java.util.List; @@ -59,7 +60,7 @@ public abstract class AbstractTestProxy extends CompositePrintable { public abstract List getAllTests(); - public void fireOnNewPrintable(final Printable printable) { + public void fireOnNewPrintable(@NotNull final Printable printable) { if (myPrinter != null) { myPrinter.onNewAvailable(printable); } @@ -78,7 +79,7 @@ public abstract class AbstractTestProxy extends CompositePrintable { * @param printable Printable info */ @Override - public void addLast(final Printable printable) { + public void addLast(@NotNull final Printable printable) { super.addLast(printable); fireOnNewPrintable(printable); } diff --git a/platform/testRunner/src/com/intellij/execution/testframework/CompositePrintable.java b/platform/testRunner/src/com/intellij/execution/testframework/CompositePrintable.java index a37168ced4a4..8d45a73ced83 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/CompositePrintable.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/CompositePrintable.java @@ -23,6 +23,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.io.FileUtil; import com.intellij.util.io.IOUtil; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; import java.io.*; import java.util.ArrayList; @@ -63,7 +64,7 @@ public class CompositePrintable implements Printable, Disposable { } } - public void addLast(final Printable printable) { + public void addLast(@NotNull final Printable printable) { synchronized (myNestedPrintables) { myNestedPrintables.add(printable); } @@ -132,7 +133,7 @@ public class CompositePrintable implements Printable, Disposable { } @Override - public void onNewAvailable(Printable printable11) { + public void onNewAvailable(@NotNull Printable printable11) { } @Override diff --git a/platform/testRunner/src/com/intellij/execution/testframework/DeferingPrinter.java b/platform/testRunner/src/com/intellij/execution/testframework/DeferingPrinter.java index 678783d4fc80..31c90f99dcde 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/DeferingPrinter.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/DeferingPrinter.java @@ -18,6 +18,7 @@ package com.intellij.execution.testframework; import com.intellij.execution.filters.HyperlinkInfo; import com.intellij.execution.ui.ConsoleViewContentType; +import org.jetbrains.annotations.NotNull; public class DeferingPrinter implements Printer { private CompositePrintable myCompositePrintable; @@ -34,7 +35,7 @@ public class DeferingPrinter implements Printer { }); } - public void onNewAvailable(final Printable printable) { + public void onNewAvailable(@NotNull final Printable printable) { myCompositePrintable.addLast(printable); } diff --git a/platform/testRunner/src/com/intellij/execution/testframework/Printer.java b/platform/testRunner/src/com/intellij/execution/testframework/Printer.java index 87d480bfb612..e147c63e3280 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/Printer.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/Printer.java @@ -17,10 +17,11 @@ package com.intellij.execution.testframework; import com.intellij.execution.filters.HyperlinkInfo; import com.intellij.execution.ui.ConsoleViewContentType; +import org.jetbrains.annotations.NotNull; public interface Printer { void print(String text, ConsoleViewContentType contentType); - void onNewAvailable(Printable printable); + void onNewAvailable(@NotNull Printable printable); void printHyperlink(String text, HyperlinkInfo info); void mark(); } From 2f951fe1d428fd91b4643598c00139461b87ed30 Mon Sep 17 00:00:00 2001 From: anna Date: Wed, 1 Sep 2010 13:58:21 +0400 Subject: [PATCH 14/15] @NotNulls --- .../execution/testframework/sm/runner/ui/MockPrinter.java | 3 ++- .../testframework/export/TestResultsXmlFormatter.java | 3 ++- .../execution/testframework/ui/TestsOutputConsolePrinter.java | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/MockPrinter.java b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/MockPrinter.java index 040e41366417..735ec75450d5 100644 --- a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/MockPrinter.java +++ b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/MockPrinter.java @@ -19,6 +19,7 @@ import com.intellij.execution.filters.HyperlinkInfo; import com.intellij.execution.testframework.Printable; import com.intellij.execution.testframework.Printer; import com.intellij.execution.ui.ConsoleViewContentType; +import org.jetbrains.annotations.NotNull; public class MockPrinter implements Printer { private boolean myShouldReset = false; @@ -81,7 +82,7 @@ public class MockPrinter implements Printer { return myHasPrinted; } - public void onNewAvailable(Printable printable) { + public void onNewAvailable(@NotNull Printable printable) { printable.printOn(this); } diff --git a/platform/testRunner/src/com/intellij/execution/testframework/export/TestResultsXmlFormatter.java b/platform/testRunner/src/com/intellij/execution/testframework/export/TestResultsXmlFormatter.java index cb7863226a23..a78426de8be7 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/export/TestResultsXmlFormatter.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/export/TestResultsXmlFormatter.java @@ -24,6 +24,7 @@ import com.intellij.execution.ui.ConsoleViewContentType; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.Ref; import com.intellij.util.PairProcessor; +import org.jetbrains.annotations.NotNull; import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; @@ -157,7 +158,7 @@ public class TestResultsXmlFormatter { } @Override - public void onNewAvailable(Printable printable) { + public void onNewAvailable(@NotNull Printable printable) { } @Override diff --git a/platform/testRunner/src/com/intellij/execution/testframework/ui/TestsOutputConsolePrinter.java b/platform/testRunner/src/com/intellij/execution/testframework/ui/TestsOutputConsolePrinter.java index 21b93561e768..ab9d370df08c 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/ui/TestsOutputConsolePrinter.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/ui/TestsOutputConsolePrinter.java @@ -21,6 +21,7 @@ import com.intellij.execution.testframework.*; import com.intellij.execution.ui.ConsoleView; import com.intellij.execution.ui.ConsoleViewContentType; import com.intellij.openapi.Disposable; +import org.jetbrains.annotations.NotNull; public class TestsOutputConsolePrinter implements Printer, Disposable { private final ConsoleView myConsole; @@ -67,7 +68,7 @@ public class TestsOutputConsolePrinter implements Printer, Disposable { myConsole.print(text, contentType); } - public void onNewAvailable(final Printable printable) { + public void onNewAvailable(@NotNull final Printable printable) { if (myPaused) { printable.printOn(myPausedPrinter); } else { From ad32aece03f278cbf659510baad43585e5cadc2f Mon Sep 17 00:00:00 2001 From: Alexey Date: Wed, 1 Sep 2010 18:47:19 +0400 Subject: [PATCH 15/15] Add new sample plugin "textEditor". --- samples/textEditor/src/META-INF/plugin.xml | 30 +++ .../src/myDocumentFiles/MyActionClass.java | 18 ++ .../src/myDocumentFiles/MyVisualPanel.java | 137 ++++++++++++ .../src/myDocumentFiles/OpenFileForm.form | 144 +++++++++++++ samples/textEditor/textEditor.iml | 13 ++ samples/textEditor/textEditor.ipr | 203 ++++++++++++++++++ 6 files changed, 545 insertions(+) create mode 100644 samples/textEditor/src/META-INF/plugin.xml create mode 100644 samples/textEditor/src/myDocumentFiles/MyActionClass.java create mode 100644 samples/textEditor/src/myDocumentFiles/MyVisualPanel.java create mode 100644 samples/textEditor/src/myDocumentFiles/OpenFileForm.form create mode 100644 samples/textEditor/textEditor.iml create mode 100644 samples/textEditor/textEditor.ipr diff --git a/samples/textEditor/src/META-INF/plugin.xml b/samples/textEditor/src/META-INF/plugin.xml new file mode 100644 index 000000000000..50e4b400af36 --- /dev/null +++ b/samples/textEditor/src/META-INF/plugin.xml @@ -0,0 +1,30 @@ + + DocumentFiles + This plugin illustrates how to work with document files. + 1.0 + JetBrains + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/textEditor/src/myDocumentFiles/MyActionClass.java b/samples/textEditor/src/myDocumentFiles/MyActionClass.java new file mode 100644 index 000000000000..1f12da711a19 --- /dev/null +++ b/samples/textEditor/src/myDocumentFiles/MyActionClass.java @@ -0,0 +1,18 @@ +package myDocumentFiles; + +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; + +/** + * Created by IntelliJ IDEA. + * User: Alexey.Chursin + * Date: Aug 30, 2010 + * Time: 6:29:02 PM + */ +public class MyActionClass extends AnAction { + public void actionPerformed(AnActionEvent e) { + MyVisualPanel myEditor = new MyVisualPanel(false); + myEditor.getPeer().setTitle("Sample Text File Editor"); + myEditor.show(); + } +} diff --git a/samples/textEditor/src/myDocumentFiles/MyVisualPanel.java b/samples/textEditor/src/myDocumentFiles/MyVisualPanel.java new file mode 100644 index 000000000000..2a627a05af2a --- /dev/null +++ b/samples/textEditor/src/myDocumentFiles/MyVisualPanel.java @@ -0,0 +1,137 @@ +package myDocumentFiles; + +import com.intellij.openapi.editor.Document; +import com.intellij.openapi.fileEditor.FileDocumentManager; +import com.intellij.openapi.ui.DialogWrapper; +import com.intellij.openapi.ui.Messages; +import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VirtualFile; + +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; + +/** + * Created by IntelliJ IDEA. + * User: Alexey.Chursin + * Date: Aug 30, 2010 + * Time: 1:42:38 PM + */ +public class MyVisualPanel extends DialogWrapper { + private JTabbedPane viewFileTab; + private JTextField fileName; + private JButton buttonBrowse; + private JTextField directoryName; + private JFileChooser fileChooser = new JFileChooser(""); + private VirtualFile selectedVFile; + private Document docFile; + // Set maximum allowed number of lines in a text file to edit. + private final int maxNumberofLines = 250; + + + private JPanel myVisualUI; + private JEditorPane myFileEditor; + private JPanel viewFilePanel; + private String initialFileContent = null; + private boolean nFocus; + + + public MyVisualPanel(boolean canBeParent) { + super(canBeParent); + init(); + + + // The Browse button listener. + buttonBrowse.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + + if (OpenFile()) { + if (docFile.getLineCount() > maxNumberofLines) { + Messages.showMessageDialog("File too long! Maximum allowed number of lines: " + + String.valueOf(maxNumberofLines) + ".\n"+ + "To change this setting, modify the MyVisualPanel.maxNumberofLines field.", "Error", Messages.getErrorIcon()); + return; + } + // Read the text file content. + initialFileContent = docFile.getText(); + // Enable the View File tab + viewFileTab.setEnabled(true); + // Fill the "File name" and "Directory" text fields. + fileName.setText(selectedVFile.getName()); + directoryName.setText(selectedVFile.getParent().getUrl()); + myFileEditor.setText(initialFileContent); + } + + + } + }); + + // The file editor focus listener. + myFileEditor.addFocusListener(new FocusAdapter() { + public void focusGained(FocusEvent e) { + if (!docFile.isWritable() && nFocus) { + nFocus = false; + Messages.showMessageDialog("This file is read-only. You cannot save your changes.", "Warning", + Messages.getWarningIcon()); + return; + + } else return; + } + }); + } + + // Display the Open dialog and open the selected file. + public boolean OpenFile() { + FileNameExtensionFilter filter = new FileNameExtensionFilter("Text files", "txt"); + fileChooser.setFileFilter(filter); + //... Open a file dialog. + int retval = fileChooser.showOpenDialog(null); + if (retval == JFileChooser.APPROVE_OPTION) { + // Get virtual file + selectedVFile = LocalFileSystem.getInstance().findFileByIoFile(fileChooser.getSelectedFile()); + // Get document file + docFile = FileDocumentManager.getInstance().getDocument(selectedVFile); + nFocus = true; + + return true; + } + viewFilePanel.setEnabled(false); + return false; + } + + + public JComponent createCenterPanel() { + + return (JComponent) myVisualUI; + + } + // The OK button handler. + protected void doOKAction() { + if (initialFileContent == null) { + this.close(0); + return; + } + if (!initialFileContent.equals(myFileEditor.getText())) { + if (Messages.showYesNoDialog("The file " + selectedVFile.getName() + + " has been changed. Are you sure you want to overwrite it?", "File Changed", Messages.getQuestionIcon()) == 0) { + if (docFile.isWritable()) { + docFile.setText(myFileEditor.getText()); + } else { + Messages.showMessageDialog("This file is read-only! You cannot save your changes.", "Error", Messages.getErrorIcon()); + return; + } + + + } else return; + } + + this.close(0); + this.dispose(); + + + } + +} diff --git a/samples/textEditor/src/myDocumentFiles/OpenFileForm.form b/samples/textEditor/src/myDocumentFiles/OpenFileForm.form new file mode 100644 index 000000000000..7e71f042101d --- /dev/null +++ b/samples/textEditor/src/myDocumentFiles/OpenFileForm.form @@ -0,0 +1,144 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/samples/textEditor/textEditor.iml b/samples/textEditor/textEditor.iml new file mode 100644 index 000000000000..09647c68eae8 --- /dev/null +++ b/samples/textEditor/textEditor.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/samples/textEditor/textEditor.ipr b/samples/textEditor/textEditor.ipr new file mode 100644 index 000000000000..a3de060824a2 --- /dev/null +++ b/samples/textEditor/textEditor.ipr @@ -0,0 +1,203 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +