mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge branch 'master' of git@git.labs.intellij.net:idea/community
This commit is contained in:
@@ -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<JDOMExternalizable> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+11
-1
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
+2
-1
@@ -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) {
|
||||
|
||||
+9
-6
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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<VirtualFile> selectedFiles) {
|
||||
ArrayList<PsiFile> result = new ArrayList<PsiFile>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
+87
@@ -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<VirtualFile> 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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+30
@@ -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);
|
||||
}
|
||||
}
|
||||
+7
-56
@@ -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<VirtualFile> selectedFiles) {
|
||||
ArrayList<PsiFile> result = new ArrayList<PsiFile>();
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+3
-3
@@ -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);
|
||||
}
|
||||
}
|
||||
+7
-1
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+5
-7
@@ -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) {
|
||||
|
||||
+3
@@ -39,4 +39,7 @@ public interface GrNewExpression extends GrCallExpression, GrConstructorCall {
|
||||
|
||||
@Nullable
|
||||
GrAnonymousClassDefinition getAnonymousClassDefinition();
|
||||
|
||||
@Nullable
|
||||
GrArrayDeclaration getArrayDeclaration();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
+22
-10
@@ -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
|
||||
|
||||
+7
-7
@@ -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);
|
||||
|
||||
+1
@@ -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 {
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
def foo(name) {
|
||||
[(name):2]
|
||||
}
|
||||
|
||||
def bar = 3+4
|
||||
def x = <selection>foo</selection>(bar)
|
||||
-----
|
||||
def foo(name) {
|
||||
[(name):2]
|
||||
}
|
||||
|
||||
def bar = 3+4
|
||||
def x = [(bar):2]
|
||||
@@ -746,7 +746,8 @@
|
||||
implementationClass="com.intellij.codeInsight.editorActions.smartEnter.JavaSmartEnterProcessor"/>
|
||||
<lang.smartEnterProcessor language="JSPX" implementationClass="com.intellij.codeInsight.completion.XmlSmartEnterProcessor"/>
|
||||
|
||||
<checkinHandlerFactory implementation="com.intellij.openapi.vcs.checkin.StandardCheckinHandlerFactory"/>
|
||||
<checkinHandlerFactory implementation="com.intellij.openapi.vcs.checkin.ReformatCheckinHandlerFactory"/>
|
||||
<checkinHandlerFactory implementation="com.intellij.openapi.vcs.checkin.OptimizeOptionsCheckinHandlerFactory"/>
|
||||
<checkinHandlerFactory implementation="com.intellij.openapi.vcs.checkin.CodeAnalysisCheckinHandlerFactory"/>
|
||||
<checkinHandlerFactory implementation="com.intellij.openapi.vcs.checkin.TodoCheckinHandlerFactory"/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user