From 436805ba4e0e2bf109e1930e0ea39bb5ed3fc5b8 Mon Sep 17 00:00:00 2001 From: Denis Zhdanov Date: Mon, 28 Mar 2011 16:01:55 +0400 Subject: [PATCH 01/12] IDEA-66438 Folding preview is displayed for a wrong folding and at a wrong place Corrected calculating of text range to show for partially displayed expanded fold region --- .../folding/impl/CodeFoldingManagerImpl.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/CodeFoldingManagerImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/CodeFoldingManagerImpl.java index ac433b3b39c0..1ab9c03a6414 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/CodeFoldingManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/CodeFoldingManagerImpl.java @@ -20,10 +20,7 @@ import com.intellij.codeInsight.folding.CodeFoldingManager; import com.intellij.codeInsight.hint.EditorFragmentComponent; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.ProjectComponent; -import com.intellij.openapi.editor.Document; -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.editor.EditorFactory; -import com.intellij.openapi.editor.FoldRegion; +import com.intellij.openapi.editor.*; import com.intellij.openapi.editor.event.EditorMouseEvent; import com.intellij.openapi.editor.event.EditorMouseEventArea; import com.intellij.openapi.editor.event.EditorMouseMotionAdapter; @@ -108,14 +105,20 @@ public class CodeFoldingManagerImpl extends CodeFoldingManager implements Projec if (psiElementRange == null) return; int textOffset = psiElementRange.getStartOffset(); - Point foldStartXY = editor.visualPositionToXY(editor.offsetToVisualPosition(textOffset)); + // There is a possible case that target PSI element's offset is less than fold region offset (e.g. complete method is + // returned as PSI element for fold region that corresponds to java method code block). We don't want to show any hint + // if start of the current fold region is displayed. + Point foldStartXY = editor.visualPositionToXY(editor.offsetToVisualPosition(Math.max(textOffset, fold.getStartOffset()))); Rectangle visibleArea = editor.getScrollingModel().getVisibleArea(); if (visibleArea.y > foldStartXY.y) { if (myCurrentHint != null) { myCurrentHint.hide(); myCurrentHint = null; } - TextRange textRange = new TextRange(textOffset, fold.getStartOffset()); + // Show only the non-displayed top part of the target fold region + int visualLine = Math.max(0, editor.xyToVisualPosition(new Point(0, visibleArea.y)).line - 1); + int endOffset = editor.logicalPositionToOffset(editor.visualToLogicalPosition(new VisualPosition(visualLine, 0))); + TextRange textRange = new TextRange(textOffset, endOffset); hint = EditorFragmentComponent.showEditorFragmentHint(editor, textRange, true, true); myCurrentFold = fold; myCurrentHint = hint; From 52505f5f12fb5f7d99d8f7b12addbee449987a29 Mon Sep 17 00:00:00 2001 From: nik Date: Mon, 28 Mar 2011 15:59:40 +0400 Subject: [PATCH 02/12] 'Exit' action enabled for running application on Mac (IDEA-56273) --- .../impl/DefaultJavaProgramRunner.java | 31 +++++++++++-------- .../runners/ProcessProxyFactoryImpl.java | 12 ++++++- .../execution/runners/ProcessProxyImpl.java | 24 ++++---------- .../runners/ProcessProxyFactory.java | 6 +++- 4 files changed, 40 insertions(+), 33 deletions(-) diff --git a/java/execution/impl/src/com/intellij/execution/impl/DefaultJavaProgramRunner.java b/java/execution/impl/src/com/intellij/execution/impl/DefaultJavaProgramRunner.java index cb3c772dd223..0d8f970ad344 100644 --- a/java/execution/impl/src/com/intellij/execution/impl/DefaultJavaProgramRunner.java +++ b/java/execution/impl/src/com/intellij/execution/impl/DefaultJavaProgramRunner.java @@ -32,10 +32,8 @@ import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.CustomShortcutSet; import com.intellij.openapi.actionSystem.Presentation; import com.intellij.openapi.fileEditor.FileDocumentManager; -import com.intellij.openapi.options.SettingsEditor; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.IconLoader; -import com.intellij.openapi.util.JDOMExternalizable; import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -52,14 +50,6 @@ public class DefaultJavaProgramRunner extends JavaPatchableProgramRunner { !(profile instanceof RunConfigurationWithSuppressedDefaultRunAction); } - public JDOMExternalizable createConfigurationData(ConfigurationInfoProvider settingsProvider) { - return null; - } - - public SettingsEditor getSettingsEditor(final Executor executor, RunConfiguration configuration) { - return null; - } - public void patch(JavaParameters javaParameters, RunnerSettings settings, final boolean beforeExecution) throws ExecutionException { runCustomPatchers(javaParameters, settings, Executor.EXECUTOR_EXTENSION_NAME.findExtension(DefaultRunExecutor.class)); } @@ -151,7 +141,7 @@ public class DefaultJavaProgramRunner extends JavaPatchableProgramRunner { public void update(final AnActionEvent event) { final Presentation presentation = event.getPresentation(); - if (ProcessProxyFactory.getInstance().getAttachedProxy(myProcessHandler) == null) { + if (!isVisible()) { presentation.setVisible(false); presentation.setEnabled(false); return; @@ -159,6 +149,10 @@ public class DefaultJavaProgramRunner extends JavaPatchableProgramRunner { presentation.setVisible(true); presentation.setEnabled(!myProcessHandler.isProcessTerminated()); } + + protected boolean isVisible() { + return ProcessProxyFactory.getInstance().getAttachedProxy(myProcessHandler) != null; + } } protected static class ControlBreakAction extends LauncherBasedAction { @@ -168,8 +162,16 @@ public class DefaultJavaProgramRunner extends JavaPatchableProgramRunner { setShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_CANCEL, InputEvent.CTRL_DOWN_MASK))); } + @Override + protected boolean isVisible() { + return super.isVisible() && ProcessProxyFactory.getInstance().isBreakGenLibraryAvailable(); + } + public void actionPerformed(final AnActionEvent e) { - ProcessProxyFactory.getInstance().getAttachedProxy(myProcessHandler).sendBreak(); + ProcessProxy proxy = ProcessProxyFactory.getInstance().getAttachedProxy(myProcessHandler); + if (proxy != null) { + proxy.sendBreak(); + } } } @@ -179,7 +181,10 @@ public class DefaultJavaProgramRunner extends JavaPatchableProgramRunner { } public void actionPerformed(final AnActionEvent e) { - ProcessProxyFactory.getInstance().getAttachedProxy(myProcessHandler).sendStop(); + ProcessProxy proxy = ProcessProxyFactory.getInstance().getAttachedProxy(myProcessHandler); + if (proxy != null) { + proxy.sendStop(); + } } } diff --git a/java/execution/impl/src/com/intellij/execution/runners/ProcessProxyFactoryImpl.java b/java/execution/impl/src/com/intellij/execution/runners/ProcessProxyFactoryImpl.java index 9f50acd77ff2..e8764d29657d 100644 --- a/java/execution/impl/src/com/intellij/execution/runners/ProcessProxyFactoryImpl.java +++ b/java/execution/impl/src/com/intellij/execution/runners/ProcessProxyFactoryImpl.java @@ -22,6 +22,10 @@ import com.intellij.execution.configurations.ParametersList; import com.intellij.execution.process.ProcessHandler; import com.intellij.openapi.projectRoots.ex.JavaSdkUtil; import com.intellij.openapi.application.PathManager; +import com.intellij.openapi.util.SystemInfo; +import org.jetbrains.annotations.NonNls; + +import java.io.File; public class ProcessProxyFactoryImpl extends ProcessProxyFactory { public ProcessProxy createCommandLineProxy(final JavaCommandLine javaCmdLine) throws ExecutionException { @@ -32,7 +36,7 @@ public class ProcessProxyFactoryImpl extends ProcessProxyFactory { final JavaParameters javaParameters = javaCmdLine.getJavaParameters(); JavaSdkUtil.addRtJar(javaParameters.getClassPath()); final ParametersList vmParametersList = javaParameters.getVMParametersList(); - vmParametersList.defineProperty(ProcessProxyImpl.PROPERTY_PORT_NUMBER, "" + proxy.getPortNumber()); + vmParametersList.defineProperty(ProcessProxyImpl.PROPERTY_PORT_NUMBER, String.valueOf(proxy.getPortNumber())); vmParametersList.defineProperty(ProcessProxyImpl.PROPERTY_BINPATH, PathManager.getBinPath()); javaParameters.getProgramParametersList().prepend(javaParameters.getMainClass()); javaParameters.setMainClass(ProcessProxyImpl.LAUNCH_MAIN_CLASS); @@ -47,4 +51,10 @@ public class ProcessProxyFactoryImpl extends ProcessProxyFactory { public ProcessProxy getAttachedProxy(final ProcessHandler processHandler) { return processHandler != null ? processHandler.getUserData(ProcessProxyImpl.KEY) : null; } + + @Override + public boolean isBreakGenLibraryAvailable() { + @NonNls final String libName = SystemInfo.isWindows ? "breakgen.dll" : "libbreakgen.so"; + return new File(PathManager.getBinPath() + File.separator + libName).exists(); + } } \ No newline at end of file diff --git a/java/execution/impl/src/com/intellij/execution/runners/ProcessProxyImpl.java b/java/execution/impl/src/com/intellij/execution/runners/ProcessProxyImpl.java index fef924b5184e..e1a5ff5810e3 100644 --- a/java/execution/impl/src/com/intellij/execution/runners/ProcessProxyImpl.java +++ b/java/execution/impl/src/com/intellij/execution/runners/ProcessProxyImpl.java @@ -16,17 +16,17 @@ package com.intellij.execution.runners; import com.intellij.execution.process.ProcessHandler; -import com.intellij.openapi.application.PathManager; import com.intellij.openapi.util.Key; -import com.intellij.openapi.util.SystemInfo; +import org.jetbrains.annotations.NonNls; -import java.io.*; +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; import java.net.InetAddress; import java.net.ServerSocket; import java.net.Socket; -import org.jetbrains.annotations.NonNls; - /** * @author ven */ @@ -112,18 +112,6 @@ class ProcessProxyImpl implements ProcessProxy { } public static boolean useLauncher() { - if (Boolean.valueOf(System.getProperty(DONT_USE_LAUNCHER_PROPERTY))) { - return false; - } - - if (!SystemInfo.isWindows && !SystemInfo.isLinux) { - return false; - } - return new File(getLaunchertLibName()).exists(); - } - - public static String getLaunchertLibName() { - @NonNls final String libName = SystemInfo.isWindows ? "breakgen.dll" : "libbreakgen.so"; - return PathManager.getBinPath() + File.separator + libName; + return !Boolean.valueOf(System.getProperty(DONT_USE_LAUNCHER_PROPERTY)); } } diff --git a/java/execution/openapi/src/com/intellij/execution/runners/ProcessProxyFactory.java b/java/execution/openapi/src/com/intellij/execution/runners/ProcessProxyFactory.java index 3488f242819b..9dd0d0444499 100644 --- a/java/execution/openapi/src/com/intellij/execution/runners/ProcessProxyFactory.java +++ b/java/execution/openapi/src/com/intellij/execution/runners/ProcessProxyFactory.java @@ -19,14 +19,18 @@ import com.intellij.execution.ExecutionException; import com.intellij.execution.configurations.JavaCommandLine; import com.intellij.execution.process.ProcessHandler; import com.intellij.openapi.components.ServiceManager; +import org.jetbrains.annotations.Nullable; public abstract class ProcessProxyFactory { + public abstract boolean isBreakGenLibraryAvailable(); + public static ProcessProxyFactory getInstance() { return ServiceManager.getService(ProcessProxyFactory.class); } - + @Nullable public abstract ProcessProxy createCommandLineProxy(JavaCommandLine javaCmdLine) throws ExecutionException; + @Nullable public abstract ProcessProxy getAttachedProxy(ProcessHandler processHandler); } \ No newline at end of file From e88d9c5e418b3979fcb2f2c87d39cc012f0aa182 Mon Sep 17 00:00:00 2001 From: Roman Chernyatchik Date: Mon, 28 Mar 2011 16:35:12 +0400 Subject: [PATCH 03/12] content size evaluation corrected in output console (part of input support in tests runner console feature) --- .../intellij/execution/impl/ConsoleViewImpl.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java b/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java index 91b44e999751..d448b1e4ab0a 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java @@ -405,7 +405,17 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo public void clear() { synchronized (LOCK) { - myContentSize = 0; + // let's decrease myContentSize by size of deferred output text + // then in EDT we will clear already flushed output (editor content) + // end it will induce document changed event which will + // also decrease myContentSize by flushed output size. + // + // P.S: We cannot set myContentSize to '0' here because between this + // code and alarm clear request (in EDT) my occur print event in non-EDT thread + // and unfortunately it is a real usecase and happens when switching active test in + // tests console. + myContentSize = Math.max(0, myContentSize - myDeferredOutputLength); + myDeferredOutput.clear(); myDeferredOutput.add(new StringBuilder(CYCLIC_BUFFER_UNIT_SIZE)); myDeferredOutputLength = 0; @@ -807,8 +817,8 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo else { for (StringBuilder builder : myDeferredOutput) { builder.setLength(0); + } } - } myDeferredOutputLength = 0; } final Document document = myEditor.getDocument(); From d8e6e046abebf44fcd1da82f0b4c802a45ddf678 Mon Sep 17 00:00:00 2001 From: anna Date: Mon, 28 Mar 2011 13:58:25 +0200 Subject: [PATCH 04/12] inplace refactorings: make final listener fixed - commit document before retrieve psi (IDEA-67146) --- .../introduceVariable/VariableInplaceIntroducer.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/java/java-impl/src/com/intellij/refactoring/introduceVariable/VariableInplaceIntroducer.java b/java/java-impl/src/com/intellij/refactoring/introduceVariable/VariableInplaceIntroducer.java index 9ae8973f4744..458667316265 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceVariable/VariableInplaceIntroducer.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceVariable/VariableInplaceIntroducer.java @@ -394,13 +394,14 @@ public class VariableInplaceIntroducer extends VariableInplaceRenamer { new WriteCommandAction(myProject){ @Override protected void run(com.intellij.openapi.application.Result result) throws Throwable { + final Document document = myEditor.getDocument(); + PsiDocumentManager.getInstance(getProject()).commitDocument(document); final PsiVariable variable = getVariable(); LOG.assertTrue(variable != null); final PsiModifierList modifierList = variable.getModifierList(); LOG.assertTrue(modifierList != null); final int textOffset = modifierList.getTextOffset(); - final Document document = myEditor.getDocument(); final Runnable runnable = new Runnable() { public void run() { if (generateFinal) { From 9dfda9c0a0b6b8882c2fcf26f49eaa82308242af Mon Sep 17 00:00:00 2001 From: anna Date: Mon, 28 Mar 2011 14:56:48 +0200 Subject: [PATCH 05/12] trigger rename listener on change signature if method name was changed (IDEA-67102) --- .../changeSignature/ChangeSignatureProcessorBase.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureProcessorBase.java b/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureProcessorBase.java index 1bfbaf318059..e86664526e18 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureProcessorBase.java +++ b/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureProcessorBase.java @@ -21,6 +21,7 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiManager; import com.intellij.refactoring.BaseRefactoringProcessor; import com.intellij.refactoring.RefactoringBundle; +import com.intellij.refactoring.listeners.RefactoringElementListener; import com.intellij.refactoring.util.MoveRenameUsageInfo; import com.intellij.usageView.UsageInfo; import com.intellij.usageView.UsageViewUtil; @@ -103,6 +104,7 @@ public abstract class ChangeSignatureProcessorBase extends BaseRefactoringProces } protected void performRefactoring(UsageInfo[] usages) { + final RefactoringElementListener elementListener = getTransaction().getElementListener(myChangeInfo.getMethod()); try { final ChangeSignatureUsageProcessor[] processors = ChangeSignatureUsageProcessor.EP_NAME.getExtensions(); @@ -123,7 +125,11 @@ public abstract class ChangeSignatureProcessorBase extends BaseRefactoringProces } } - LOG.assertTrue(myChangeInfo.getMethod().isValid()); + final PsiElement method = myChangeInfo.getMethod(); + LOG.assertTrue(method.isValid()); + if (myChangeInfo.isNameChanged()) { + elementListener.elementRenamed(method); + } } catch (IncorrectOperationException e) { LOG.error(e); From f2f3983054b5e2b5ec9f81627eb1cb5dad3b4eb9 Mon Sep 17 00:00:00 2001 From: Oleg Shpynov Date: Mon, 28 Mar 2011 17:14:07 +0400 Subject: [PATCH 06/12] Decouple Optimize imports and reformat code checkin handlers --- .../vcs/checkin/BeforeCheckinHandlerUtil.java | 59 +++++++++++++ .../OptimizeImportsBeforeCheckinHandler.java | 87 +++++++++++++++++++ .../OptimizeOptionsCheckinHandlerFactory.java | 30 +++++++ ...java => ReformatBeforeCheckinHandler.java} | 63 ++------------ ...ava => ReformatCheckinHandlerFactory.java} | 6 +- resources/src/META-INF/IdeaPlugin.xml | 3 +- 6 files changed, 188 insertions(+), 60 deletions(-) create mode 100644 platform/lang-impl/src/com/intellij/openapi/vcs/checkin/BeforeCheckinHandlerUtil.java create mode 100644 platform/lang-impl/src/com/intellij/openapi/vcs/checkin/OptimizeImportsBeforeCheckinHandler.java create mode 100644 platform/lang-impl/src/com/intellij/openapi/vcs/checkin/OptimizeOptionsCheckinHandlerFactory.java rename platform/lang-impl/src/com/intellij/openapi/vcs/checkin/{StandardBeforeCheckinHandler.java => ReformatBeforeCheckinHandler.java} (53%) rename platform/lang-impl/src/com/intellij/openapi/vcs/checkin/{StandardCheckinHandlerFactory.java => ReformatCheckinHandlerFactory.java} (87%) diff --git a/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/BeforeCheckinHandlerUtil.java b/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/BeforeCheckinHandlerUtil.java new file mode 100644 index 000000000000..5e15f0dab578 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/BeforeCheckinHandlerUtil.java @@ -0,0 +1,59 @@ +/* + * Copyright 2000-2011 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.openapi.vcs.checkin; + +import com.intellij.openapi.components.StorageScheme; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.project.ex.ProjectEx; +import com.intellij.openapi.vfs.VfsUtil; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.PsiFile; +import com.intellij.psi.PsiManager; +import com.intellij.psi.util.PsiUtilBase; + +import java.util.ArrayList; +import java.util.Collection; + +/** + * @author oleg + */ +public class BeforeCheckinHandlerUtil { + + public static PsiFile[] getPsiFiles(final Project myProject, final Collection selectedFiles) { + ArrayList result = new ArrayList(); + PsiManager psiManager = PsiManager.getInstance(myProject); + + VirtualFile projectFileDir = null; + final StorageScheme storageScheme = ((ProjectEx) myProject).getStateStore().getStorageScheme(); + if (StorageScheme.DIRECTORY_BASED.equals(storageScheme)) { + VirtualFile baseDir = myProject.getBaseDir(); + if (baseDir != null) { + projectFileDir = baseDir.findChild(Project.DIRECTORY_STORE_FOLDER); + } + } + + for (VirtualFile file : selectedFiles) { + if (file.isValid()) { + if (projectFileDir != null && VfsUtil.isAncestor(projectFileDir, file, false)) { + continue; + } + PsiFile psiFile = psiManager.findFile(file); + if (psiFile != null) result.add(psiFile); + } + } + return PsiUtilBase.toPsiFileArray(result); + } +} diff --git a/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/OptimizeImportsBeforeCheckinHandler.java b/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/OptimizeImportsBeforeCheckinHandler.java new file mode 100644 index 000000000000..cb7390cd151d --- /dev/null +++ b/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/OptimizeImportsBeforeCheckinHandler.java @@ -0,0 +1,87 @@ +/* + * Copyright 2000-2011 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.openapi.vcs.checkin; + +import com.intellij.codeInsight.actions.OptimizeImportsProcessor; +import com.intellij.openapi.fileEditor.FileDocumentManager; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vcs.CheckinProjectPanel; +import com.intellij.openapi.vcs.VcsBundle; +import com.intellij.openapi.vcs.VcsConfiguration; +import com.intellij.openapi.vcs.ui.RefreshableOnComponent; +import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; +import java.awt.*; +import java.util.Collection; + +public class OptimizeImportsBeforeCheckinHandler extends CheckinHandler implements CheckinMetaHandler { + protected final Project myProject; + private final CheckinProjectPanel myPanel; + + public OptimizeImportsBeforeCheckinHandler(final Project project, final CheckinProjectPanel panel) { + myProject = project; + myPanel = panel; + } + + @Nullable + public RefreshableOnComponent getBeforeCheckinConfigurationPanel() { + final JCheckBox optimizeBox = new JCheckBox(VcsBundle.message("checkbox.checkin.options.optimize.imports")); + + return new RefreshableOnComponent() { + public JComponent getComponent() { + final JPanel panel = new JPanel(new GridLayout(1, 0)); + panel.add(optimizeBox); + return panel; + } + + public void refresh() { + } + + public void saveState() { + getSettings().OPTIMIZE_IMPORTS_BEFORE_PROJECT_COMMIT = optimizeBox.isSelected(); + } + + public void restoreState() { + optimizeBox.setSelected(getSettings().OPTIMIZE_IMPORTS_BEFORE_PROJECT_COMMIT); + } + }; + + } + + protected VcsConfiguration getSettings() { + return VcsConfiguration.getInstance(myProject); + } + + public void runCheckinHandlers(final Runnable finishAction) { + final VcsConfiguration configuration = VcsConfiguration.getInstance(myProject); + final Collection files = myPanel.getVirtualFiles(); + + final Runnable performCheckoutAction = new Runnable() { + public void run() { + FileDocumentManager.getInstance().saveAllDocuments(); + finishAction.run(); + } + }; + + if (configuration.OPTIMIZE_IMPORTS_BEFORE_PROJECT_COMMIT) { + new OptimizeImportsProcessor(myProject, BeforeCheckinHandlerUtil.getPsiFiles(myProject, files), performCheckoutAction).run(); + } + + } +} diff --git a/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/OptimizeOptionsCheckinHandlerFactory.java b/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/OptimizeOptionsCheckinHandlerFactory.java new file mode 100644 index 000000000000..87f3bebcfc21 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/OptimizeOptionsCheckinHandlerFactory.java @@ -0,0 +1,30 @@ +/* + * Copyright 2000-2011 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.openapi.vcs.checkin; + +import com.intellij.openapi.vcs.CheckinProjectPanel; +import org.jetbrains.annotations.NotNull; + +/** + * @author oleg + */ +public class OptimizeOptionsCheckinHandlerFactory extends CheckinHandlerFactory { + @NotNull + public CheckinHandler createHandler(final CheckinProjectPanel panel) { + return new OptimizeImportsBeforeCheckinHandler(panel.getProject(), panel); + } +} \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/StandardBeforeCheckinHandler.java b/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/ReformatBeforeCheckinHandler.java similarity index 53% rename from platform/lang-impl/src/com/intellij/openapi/vcs/checkin/StandardBeforeCheckinHandler.java rename to platform/lang-impl/src/com/intellij/openapi/vcs/checkin/ReformatBeforeCheckinHandler.java index 21a4483b75f9..56f4dc29da38 100644 --- a/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/StandardBeforeCheckinHandler.java +++ b/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/ReformatBeforeCheckinHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -16,46 +16,36 @@ package com.intellij.openapi.vcs.checkin; -import com.intellij.codeInsight.actions.OptimizeImportsProcessor; import com.intellij.codeInsight.actions.ReformatCodeProcessor; -import com.intellij.openapi.components.StorageScheme; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.project.Project; -import com.intellij.openapi.project.ex.ProjectEx; import com.intellij.openapi.vcs.CheckinProjectPanel; import com.intellij.openapi.vcs.VcsBundle; import com.intellij.openapi.vcs.VcsConfiguration; import com.intellij.openapi.vcs.ui.RefreshableOnComponent; -import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiManager; -import com.intellij.psi.util.PsiUtilBase; import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; -import java.util.ArrayList; import java.util.Collection; -public class StandardBeforeCheckinHandler extends CheckinHandler implements CheckinMetaHandler { +public class ReformatBeforeCheckinHandler extends CheckinHandler implements CheckinMetaHandler { protected final Project myProject; private final CheckinProjectPanel myPanel; - public StandardBeforeCheckinHandler(final Project project, final CheckinProjectPanel panel) { + public ReformatBeforeCheckinHandler(final Project project, final CheckinProjectPanel panel) { myProject = project; myPanel = panel; } @Nullable public RefreshableOnComponent getBeforeCheckinConfigurationPanel() { - final JCheckBox optimizeBox = new JCheckBox(VcsBundle.message("checkbox.checkin.options.optimize.imports")); final JCheckBox reformatBox = new JCheckBox(VcsBundle.message("checkbox.checkin.options.reformat.code")); return new RefreshableOnComponent() { public JComponent getComponent() { - final JPanel panel = new JPanel(new GridLayout(2, 0)); - panel.add(optimizeBox); + final JPanel panel = new JPanel(new GridLayout(1, 0)); panel.add(reformatBox); return panel; } @@ -64,12 +54,10 @@ public class StandardBeforeCheckinHandler extends CheckinHandler implements Chec } public void saveState() { - getSettings().OPTIMIZE_IMPORTS_BEFORE_PROJECT_COMMIT = optimizeBox.isSelected(); getSettings().REFORMAT_BEFORE_PROJECT_COMMIT = reformatBox.isSelected(); } public void restoreState() { - optimizeBox.setSelected(getSettings().OPTIMIZE_IMPORTS_BEFORE_PROJECT_COMMIT); reformatBox.setSelected(getSettings().REFORMAT_BEFORE_PROJECT_COMMIT); } }; @@ -91,22 +79,11 @@ public class StandardBeforeCheckinHandler extends CheckinHandler implements Chec } }; - final Runnable reformatCodeAndPerformCheckout = new Runnable() { - public void run() { - if (reformat(configuration, true)) { - new ReformatCodeProcessor(myProject, getPsiFiles(files), performCheckoutAction).run(); - } - else { - performCheckoutAction.run(); - } - } - }; - - if (configuration.OPTIMIZE_IMPORTS_BEFORE_PROJECT_COMMIT) { - new OptimizeImportsProcessor(myProject, getPsiFiles(files), reformatCodeAndPerformCheckout).run(); + if (reformat(configuration, true)) { + new ReformatCodeProcessor(myProject, BeforeCheckinHandlerUtil.getPsiFiles(myProject, files), performCheckoutAction).run(); } else { - reformatCodeAndPerformCheckout.run(); + performCheckoutAction.run(); } } @@ -115,30 +92,4 @@ public class StandardBeforeCheckinHandler extends CheckinHandler implements Chec return checkinProject ? configuration.REFORMAT_BEFORE_PROJECT_COMMIT : configuration.REFORMAT_BEFORE_FILE_COMMIT; } - private PsiFile[] getPsiFiles(Collection selectedFiles) { - ArrayList result = new ArrayList(); - PsiManager psiManager = PsiManager.getInstance(myProject); - - VirtualFile projectFileDir = null; - final StorageScheme storageScheme = ((ProjectEx) myProject).getStateStore().getStorageScheme(); - if (StorageScheme.DIRECTORY_BASED.equals(storageScheme)) { - VirtualFile baseDir = myProject.getBaseDir(); - if (baseDir != null) { - projectFileDir = baseDir.findChild(Project.DIRECTORY_STORE_FOLDER); - } - } - - for (VirtualFile file : selectedFiles) { - if (file.isValid()) { - if (projectFileDir != null && VfsUtil.isAncestor(projectFileDir, file, false)) { - continue; - } - PsiFile psiFile = psiManager.findFile(file); - if (psiFile != null) result.add(psiFile); - } - } - return PsiUtilBase.toPsiFileArray(result); - } - - } diff --git a/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/StandardCheckinHandlerFactory.java b/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/ReformatCheckinHandlerFactory.java similarity index 87% rename from platform/lang-impl/src/com/intellij/openapi/vcs/checkin/StandardCheckinHandlerFactory.java rename to platform/lang-impl/src/com/intellij/openapi/vcs/checkin/ReformatCheckinHandlerFactory.java index 6a50b493c544..1694cf3335f9 100644 --- a/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/StandardCheckinHandlerFactory.java +++ b/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/ReformatCheckinHandlerFactory.java @@ -16,15 +16,15 @@ package com.intellij.openapi.vcs.checkin; -import org.jetbrains.annotations.NotNull; import com.intellij.openapi.vcs.CheckinProjectPanel; +import org.jetbrains.annotations.NotNull; /** * @author yole */ -public class StandardCheckinHandlerFactory extends CheckinHandlerFactory { +public class ReformatCheckinHandlerFactory extends CheckinHandlerFactory { @NotNull public CheckinHandler createHandler(final CheckinProjectPanel panel) { - return new StandardBeforeCheckinHandler(panel.getProject(), panel); + return new ReformatBeforeCheckinHandler(panel.getProject(), panel); } } \ No newline at end of file diff --git a/resources/src/META-INF/IdeaPlugin.xml b/resources/src/META-INF/IdeaPlugin.xml index df485bacd239..3716378bf3d2 100644 --- a/resources/src/META-INF/IdeaPlugin.xml +++ b/resources/src/META-INF/IdeaPlugin.xml @@ -746,7 +746,8 @@ implementationClass="com.intellij.codeInsight.editorActions.smartEnter.JavaSmartEnterProcessor"/> - + + From 2865191ee29ea7bd38b350e0863b0f0319adf69f Mon Sep 17 00:00:00 2001 From: anna Date: Mon, 28 Mar 2011 15:40:30 +0200 Subject: [PATCH 07/12] enable copy reference action for packages (IDEA-12639 ) --- .../src/com/intellij/ide/actions/JavaQualifiedNameProvider.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/java/java-impl/src/com/intellij/ide/actions/JavaQualifiedNameProvider.java b/java/java-impl/src/com/intellij/ide/actions/JavaQualifiedNameProvider.java index 347038e43845..fed091518791 100644 --- a/java/java-impl/src/com/intellij/ide/actions/JavaQualifiedNameProvider.java +++ b/java/java-impl/src/com/intellij/ide/actions/JavaQualifiedNameProvider.java @@ -46,6 +46,7 @@ public class JavaQualifiedNameProvider implements QualifiedNameProvider { @Nullable public PsiElement adjustElementToCopy(final PsiElement element) { + if (element instanceof PsiPackage) return element; if (element != null && !(element instanceof PsiMember) && element.getParent() instanceof PsiMember) { return element.getParent(); } @@ -54,6 +55,7 @@ public class JavaQualifiedNameProvider implements QualifiedNameProvider { @Nullable public String getQualifiedName(PsiElement element) { + if (element instanceof PsiPackage) return ((PsiPackage)element).getQualifiedName(); element = getMember(element); if (element instanceof PsiClass) { return ((PsiClass)element).getQualifiedName(); From e283930effc419ce95346b368e99a0e1c44a4aa8 Mon Sep 17 00:00:00 2001 From: Maxim Medvedev Date: Mon, 28 Mar 2011 12:39:35 +0400 Subject: [PATCH 08/12] GrNewExpression api --- .../expressions/GrNewExpression.java | 3 ++ .../expressions/GrNewExpressionImpl.java | 32 +++++++++++++------ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/expressions/GrNewExpression.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/expressions/GrNewExpression.java index 8db00b5e3856..fef3d22f2fc7 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/expressions/GrNewExpression.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/expressions/GrNewExpression.java @@ -39,4 +39,7 @@ public interface GrNewExpression extends GrCallExpression, GrConstructorCall { @Nullable GrAnonymousClassDefinition getAnonymousClassDefinition(); + + @Nullable + GrArrayDeclaration getArrayDeclaration(); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrNewExpressionImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrNewExpressionImpl.java index 1c738cb0bf50..8c275f2221e1 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrNewExpressionImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrNewExpressionImpl.java @@ -92,8 +92,10 @@ public class GrNewExpressionImpl extends GrCallExpressionImpl implements GrNewEx final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(getProject()); final GrArgumentList newList = factory.createExpressionArgumentList(); PsiElement last = getLastChild(); + assert last != null; while (last.getPrevSibling() instanceof PsiWhiteSpace || last.getPrevSibling() instanceof PsiErrorElement) { last = last.getPrevSibling(); + assert last != null; } ASTNode astNode = last.getNode(); assert astNode != null; @@ -133,12 +135,16 @@ public class GrNewExpressionImpl extends GrCallExpressionImpl implements GrNewEx final GroovyResolveResult[] classResults = ref.multiResolve(false); if (classResults.length == 0) return GroovyResolveResult.EMPTY_ARRAY; - if (getNamedArguments().length > 0 && getArgumentList().getExpressionArguments().length == 0) { + final GrArgumentList argumentList = getArgumentList(); + assert argumentList != null; + + if (getNamedArguments().length > 0 && argumentList.getExpressionArguments().length == 0) { GroovyResolveResult[] constructorResults = PsiUtil.getConstructorCandidates(ref, classResults, new PsiType[]{PsiUtil.createMapType( getResolveScope())}); //one Map parameter, actually for (GroovyResolveResult result : constructorResults) { - if (result.getElement() instanceof PsiMethod) { - PsiMethod constructor = (PsiMethod)result.getElement(); + final PsiElement resolved = result.getElement(); + if (resolved instanceof PsiMethod) { + PsiMethod constructor = (PsiMethod)resolved; final PsiParameter[] parameters = constructor.getParameterList().getParameters(); if (parameters.length == 1 && InheritanceUtil.isInheritor(parameters[0].getType(), CommonClassNames.JAVA_UTIL_MAP)) { return constructorResults; @@ -155,11 +161,11 @@ public class GrNewExpressionImpl extends GrCallExpressionImpl implements GrNewEx } public GroovyResolveResult[] multiResolveClass() { - return getReferenceElement().multiResolve(false); - } - - public PsiMethod resolveConstructor() { - return PsiImplUtil.extractUniqueElement(multiResolveConstructor()); + final GrCodeReferenceElement referenceElement = getReferenceElement(); + if (referenceElement != null) { + return referenceElement.multiResolve(false); + } + return GroovyResolveResult.EMPTY_ARRAY; } @NotNull @@ -168,7 +174,7 @@ public class GrNewExpressionImpl extends GrCallExpressionImpl implements GrNewEx } public int getArrayCount() { - final GrArrayDeclaration arrayDeclaration = findChildByClass(GrArrayDeclaration.class); + final GrArrayDeclaration arrayDeclaration = getArrayDeclaration(); if (arrayDeclaration == null) return 0; return arrayDeclaration.getArrayCount(); } @@ -177,9 +183,15 @@ public class GrNewExpressionImpl extends GrCallExpressionImpl implements GrNewEx return findChildByClass(GrAnonymousClassDefinition.class); } + @Nullable + @Override + public GrArrayDeclaration getArrayDeclaration() { + return findChildByClass(GrArrayDeclaration.class); + } + @Nullable public PsiMethod resolveMethod() { - return resolveConstructor(); + return PsiImplUtil.extractUniqueElement(multiResolveConstructor()); } @NotNull From 732a71fcd94e3b3f16fe805938801041ddda51cc Mon Sep 17 00:00:00 2001 From: Maxim Medvedev Date: Mon, 28 Mar 2011 12:47:49 +0400 Subject: [PATCH 09/12] don't use old GrNewExpression api --- .../groovy/lang/resolve/ResolveMethodTest.groovy | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolveMethodTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolveMethodTest.groovy index 87ec00fe9302..f15045c62287 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolveMethodTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolveMethodTest.groovy @@ -227,14 +227,14 @@ public class ResolveMethodTest extends GroovyResolveTestCase { public void testConstructor() throws Exception { PsiReference ref = configureByFile("constructor/A.groovy"); - PsiMethod resolved = ((GrNewExpression) ref.getElement().getParent()).resolveConstructor(); + PsiMethod resolved = ((GrNewExpression) ref.getElement().getParent()).resolveMethod(); assertNotNull(resolved); assertTrue(resolved.isConstructor()); } public void testConstructor1() throws Exception { PsiReference ref = configureByFile("constructor1/A.groovy"); - PsiMethod method = ((GrNewExpression) ref.getElement().getParent()).resolveConstructor(); + PsiMethod method = ((GrNewExpression) ref.getElement().getParent()).resolveMethod(); assertNotNull(method); assertTrue(method.isConstructor()); assertEquals(0, method.getParameterList().getParameters().length); @@ -242,14 +242,14 @@ public class ResolveMethodTest extends GroovyResolveTestCase { public void testConstructor2() throws Exception { PsiReference ref = configureByFile("constructor2/A.groovy"); - PsiMethod method = ((GrNewExpression) ref.getElement().getParent()).resolveConstructor(); + PsiMethod method = ((GrNewExpression) ref.getElement().getParent()).resolveMethod(); assertNull(method); } //grvy-101 public void testConstructor3() throws Exception { PsiReference ref = configureByFile("constructor3/A.groovy"); - PsiMethod method = ((GrNewExpression) ref.getElement().getParent()).resolveConstructor(); + PsiMethod method = ((GrNewExpression) ref.getElement().getParent()).resolveMethod(); assertNotNull(method); assertTrue(method.isConstructor()); assertEquals(0, method.getParameterList().getParameters().length); @@ -287,7 +287,7 @@ public class ResolveMethodTest extends GroovyResolveTestCase { public void testEmptyVsMap() throws Exception { PsiReference ref = configureByFile("emptyVsMap/A.groovy"); - PsiMethod resolved = ((GrNewExpression) ref.getElement().getParent()).resolveConstructor(); + PsiMethod resolved = ((GrNewExpression) ref.getElement().getParent()).resolveMethod(); assertNotNull(resolved); assertEquals(0, resolved.getParameterList().getParametersCount()); } @@ -304,7 +304,7 @@ public class ResolveMethodTest extends GroovyResolveTestCase { public void testAliasedConstructor() throws Exception { PsiReference ref = configureByFile("aliasedConstructor/A.groovy"); - PsiMethod resolved = ((GrNewExpression) ref.getElement().getParent()).resolveConstructor(); + PsiMethod resolved = ((GrNewExpression) ref.getElement().getParent()).resolveMethod(); assertNotNull(resolved); assertEquals("JFrame", resolved.getName()); } @@ -312,7 +312,7 @@ public class ResolveMethodTest extends GroovyResolveTestCase { public void testFixedVsVarargs1() throws Exception { PsiReference ref = configureByFile("fixedVsVarargs1/A.groovy"); - PsiMethod resolved = ((GrNewExpression) ref.getElement().getParent()).resolveConstructor(); + PsiMethod resolved = ((GrNewExpression) ref.getElement().getParent()).resolveMethod(); assertNotNull(resolved); final GrParameter[] parameters = ((GrMethod) resolved).getParameters(); assertEquals(parameters.length, 1); From 9c350f87dadf29756ea6e4da12372b8f040d3dd3 Mon Sep 17 00:00:00 2001 From: Maxim Medvedev Date: Mon, 28 Mar 2011 14:51:28 +0400 Subject: [PATCH 10/12] IDEA-66809 Inline method changes map key semantics --- .../plugins/groovy/lang/psi/impl/PsiImplUtil.java | 5 ++++- .../groovy/refactoring/inline/InlineMethodTest.java | 1 + .../groovy/refactoring/inlineMethod/namedArg.test | 13 +++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 plugins/groovy/testdata/groovy/refactoring/inlineMethod/namedArg.test diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/PsiImplUtil.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/PsiImplUtil.java index 3a617bcde545..45adc462a6fc 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/PsiImplUtil.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/PsiImplUtil.java @@ -43,6 +43,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentLabel; import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList; import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock; import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrCodeBlock; @@ -83,7 +84,9 @@ public class PsiImplUtil { } // Remove unnecessary parentheses - if (removeUnnecessaryParentheses && oldParent instanceof GrParenthesizedExpression) { + if (removeUnnecessaryParentheses && + oldParent instanceof GrParenthesizedExpression && + !(oldParent.getParent() instanceof GrArgumentLabel)) { return ((GrExpression)oldParent).replaceWithExpression(newExpr, removeUnnecessaryParentheses); } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/inline/InlineMethodTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/inline/InlineMethodTest.java index 87de00c74412..223f8a197412 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/inline/InlineMethodTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/inline/InlineMethodTest.java @@ -96,6 +96,7 @@ public class InlineMethodTest extends LightCodeInsightFixtureTestCase { public void testFieldAsParameter() throws Throwable { doTest(); } public void testWritableVariable() throws Throwable { doTest(); } public void testSingleExpression() {doTest();} + public void testNamedArg() {doTest();} public void _testInlineInGString() throws Throwable {doTest(); } public void testInlineAll() throws Throwable { diff --git a/plugins/groovy/testdata/groovy/refactoring/inlineMethod/namedArg.test b/plugins/groovy/testdata/groovy/refactoring/inlineMethod/namedArg.test new file mode 100644 index 000000000000..e465422749b1 --- /dev/null +++ b/plugins/groovy/testdata/groovy/refactoring/inlineMethod/namedArg.test @@ -0,0 +1,13 @@ +def foo(name) { + [(name):2] +} + +def bar = 3+4 +def x = foo(bar) +----- +def foo(name) { + [(name):2] +} + +def bar = 3+4 +def x = [(bar):2] \ No newline at end of file From fbf2ac9fda9b6073fc6d1f441eabfeb17275c93d Mon Sep 17 00:00:00 2001 From: Maxim Medvedev Date: Mon, 28 Mar 2011 16:56:22 +0400 Subject: [PATCH 11/12] EA-26168 - NPE: CreateClassActionBase.getText --- .../jetbrains/plugins/groovy/annotator/GroovyAnnotator.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java index 47cce3e2ec68..1c35a6ec49f9 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java @@ -1538,7 +1538,8 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator { GrPackageDefinition packageDefinition = PsiTreeUtil.getParentOfType(refElement, GrPackageDefinition.class); if (packageDefinition == null && refElement.getQualifier() == null) { PsiElement parent = refElement.getParent(); - if (parent instanceof GrNewExpression) { + if (parent instanceof GrNewExpression && + refElement.getManager().areElementsEquivalent(((GrNewExpression)parent).getReferenceElement(), refElement)) { annotation.registerFix(CreateClassFix.createClassFromNewAction((GrNewExpression)parent)); } else { From 941adce9cfa3cc8b37983f50d519943e4c79ac1b Mon Sep 17 00:00:00 2001 From: Maxim Medvedev Date: Mon, 28 Mar 2011 16:57:55 +0400 Subject: [PATCH 12/12] EA-26202 - CCE: EquivalenceChecker.expressionsAreEquivalent --- .../codeInspection/utils/EquivalenceChecker.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/utils/EquivalenceChecker.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/utils/EquivalenceChecker.java index 23587b4ae95e..63e414c98baf 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/utils/EquivalenceChecker.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/utils/EquivalenceChecker.java @@ -35,9 +35,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrForClause; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.*; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.arithmetic.GrRangeExpression; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrCallExpression; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrIndexProperty; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrPropertySelection; import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter; import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil; @@ -448,8 +446,8 @@ public class EquivalenceChecker { final String text2 = expToCompare2.getText(); return text1.equals(text2); case CALL_EXPRESSION: - return methodCallExpressionsAreEquivalent((GrMethodCallExpression) expToCompare1, - (GrMethodCallExpression) expToCompare2); + return methodCallExpressionsAreEquivalent((GrMethodCall) expToCompare1, + (GrMethodCall) expToCompare2); case NEW_EXPRESSION: return newExpressionsAreEquivalent((GrNewExpression) expToCompare1, (GrNewExpression) expToCompare2); @@ -584,8 +582,8 @@ public class EquivalenceChecker { return typesAreEquivalent(safe1, safe2); } - private static boolean methodCallExpressionsAreEquivalent(@NotNull GrMethodCallExpression methodExp1, - @NotNull GrMethodCallExpression methodExp2) { + private static boolean methodCallExpressionsAreEquivalent(@NotNull GrMethodCall methodExp1, + @NotNull GrMethodCall methodExp2) { final GrExpression methodExpression1 = methodExp1.getInvokedExpression(); final GrExpression methodExpression2 = methodExp2.getInvokedExpression(); if (!expressionsAreEquivalent(methodExpression1, methodExpression2)) { @@ -844,7 +842,7 @@ public class EquivalenceChecker { if (exp instanceof GrNewExpression) { return NEW_EXPRESSION; } - if (exp instanceof GrCallExpression) { + if (exp instanceof GrMethodCall) { return CALL_EXPRESSION; } if (exp instanceof GrPostfixExpression) {