From 6fd33267a9b8ea3dd9556bcfe1a0b22d847ddf7c Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Thu, 2 Feb 2012 14:44:51 +0400 Subject: [PATCH 01/43] check for invalid symlinks --- .../openapi/vfs/impl/win32/Win32LocalFileSystem.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/win32/Win32LocalFileSystem.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/win32/Win32LocalFileSystem.java index c69ca7f5379c..81e6f06cf1c4 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/win32/Win32LocalFileSystem.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/win32/Win32LocalFileSystem.java @@ -20,6 +20,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.impl.local.LocalFileSystemBase; +import com.intellij.util.ArrayUtil; import org.jetbrains.annotations.NotNull; import java.io.FileNotFoundException; @@ -91,6 +92,10 @@ public class Win32LocalFileSystem extends LocalFileSystemBase { @NotNull @Override public String[] list(@NotNull VirtualFile file) { + if (isInvalidSymLink(file)) { + return ArrayUtil.EMPTY_STRING_ARRAY; + } + try { String[] strings = myKernel.list(file.getPath()); if (checkMe && !Arrays.asList(strings).equals(Arrays.asList(super.list(file)))) { From bcd89a816b42e8f4a2498440708b51e3fe3787a0 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Thu, 2 Feb 2012 16:13:43 +0400 Subject: [PATCH 02/43] log if not passed --- .../com/intellij/openapi/vfs/local/SymLinkHandlingTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/SymLinkHandlingTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/SymLinkHandlingTest.java index c76e5a112113..a3ea474cd6c9 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/SymLinkHandlingTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/SymLinkHandlingTest.java @@ -44,7 +44,10 @@ public class SymLinkHandlingTest extends LightPlatformLangTestCase { } public void testBadLinksAreIgnored() throws Exception { - if (!SystemInfo.areSymLinksSupported) return; + if (!SystemInfo.areSymLinksSupported) { + System.out.println("Test not passed"); + return; + } final File missingFile = new File(FileUtil.getTempDirectory(), "missing_file"); assertTrue(missingFile.getAbsolutePath(), !missingFile.exists() || missingFile.delete()); From e73e239151f0e33ee015b1cc9c0fae19a3ee6d06 Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Thu, 2 Feb 2012 13:37:31 +0100 Subject: [PATCH 03/43] Robust location of ps command. Just 'ps' doesn't work sometimes (RUBY-10022). --- .../intellij/execution/process/UnixProcessManager.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/platform/util/src/com/intellij/execution/process/UnixProcessManager.java b/platform/util/src/com/intellij/execution/process/UnixProcessManager.java index 965953f761b2..3a695a6f8256 100644 --- a/platform/util/src/com/intellij/execution/process/UnixProcessManager.java +++ b/platform/util/src/com/intellij/execution/process/UnixProcessManager.java @@ -172,14 +172,18 @@ public class UnixProcessManager { } public static String[] getPSCmd(boolean commandLineOnly) { + String psCommand = "/bin/ps"; + if (!new File(psCommand).isFile()) { + psCommand = "ps"; + } if (SystemInfo.isLinux) { - return new String[]{"ps", "-e", "e", "--format", commandLineOnly ? "%a" : "%P%p%a"}; + return new String[]{psCommand, "-e", "e", "--format", commandLineOnly ? "%a" : "%P%p%a"}; } else if (SystemInfo.isMac) { - return new String[]{"ps", "-ax", "-E", "-o", commandLineOnly ? "command" : "ppid,pid,command"}; + return new String[]{psCommand, "-ax", "-E", "-o", commandLineOnly ? "command" : "ppid,pid,command"}; } else if (SystemInfo.isFreeBSD) { - return new String[]{"ps", "-ax", "-e", "-o", commandLineOnly ? "command" : "ppid,pid,command"}; + return new String[]{psCommand, "-ax", "-e", "-o", commandLineOnly ? "command" : "ppid,pid,command"}; } else { throw new IllegalStateException(System.getProperty("os.name") + " is not supported."); From a7dcb8205a2da668e1e515b1315387d4768393b6 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 2 Feb 2012 16:06:38 +0400 Subject: [PATCH 04/43] rename directory with module inside (IDEA-68988) --- .../openapi/module/ModifiableModuleModel.java | 2 + .../openapi/module/impl/ModuleImpl.java | 39 +++++++++++++++++++ .../module/impl/ModuleManagerImpl.java | 6 +++ .../roots/impl/storage/ClasspathStorage.java | 13 +++++++ .../storage/ClasspathStorageProvider.java | 2 + .../EclipseClasspathStorageProvider.java | 8 ++++ 6 files changed, 70 insertions(+) diff --git a/platform/lang-api/src/com/intellij/openapi/module/ModifiableModuleModel.java b/platform/lang-api/src/com/intellij/openapi/module/ModifiableModuleModel.java index bf7df2e7e171..4f33e81c9f68 100644 --- a/platform/lang-api/src/com/intellij/openapi/module/ModifiableModuleModel.java +++ b/platform/lang-api/src/com/intellij/openapi/module/ModifiableModuleModel.java @@ -137,4 +137,6 @@ public interface ModifiableModuleModel { boolean hasModuleGroups(); void setModuleGroupPath(Module module, String[] groupPath); + + void setModuleFilePath(Module module, String oldPath, String newFilePath); } diff --git a/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleImpl.java b/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleImpl.java index 423711e8b47c..f8dda219271d 100644 --- a/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleImpl.java +++ b/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleImpl.java @@ -29,6 +29,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.AreaInstance; import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.extensions.Extensions; +import com.intellij.openapi.module.ModifiableModuleModel; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleComponent; import com.intellij.openapi.module.impl.scopes.ModuleWithDependenciesScope; @@ -36,6 +37,7 @@ import com.intellij.openapi.module.impl.scopes.ModuleWithDependentsScope; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.impl.storage.ClasspathStorage; import com.intellij.openapi.util.Comparing; +import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.*; import com.intellij.psi.search.GlobalSearchScope; @@ -329,6 +331,20 @@ public class ModuleImpl extends ComponentManagerImpl implements Module { final Object requestor = event.getRequestor(); if (MODULE_RENAMING_REQUESTOR.equals(requestor)) return; if (!VirtualFile.PROP_NAME.equals(event.getPropertyName())) return; + + final VirtualFile parent = event.getParent(); + if (parent != null) { + final String parentPath = parent.getPath(); + final String ancestorPath = parentPath + "/" + event.getOldValue(); + final String moduleFilePath = getModuleFilePath(); + if (VfsUtil.isAncestor(new File(ancestorPath), new File(moduleFilePath), true)) { + final String newValue = (String)event.getNewValue(); + final String relativePath = FileUtil.getRelativePath(ancestorPath, moduleFilePath, '/'); + final String newFilePath = parentPath + "/" + newValue + "/" + relativePath; + setModuleFilePath(moduleFilePath, newFilePath); + } + } + final VirtualFile moduleFile = getModuleFile(); if (moduleFile == null) return; if (moduleFile.equals(event.getFile())) { @@ -336,6 +352,29 @@ public class ModuleImpl extends ComponentManagerImpl implements Module { ModuleManagerImpl.getInstanceImpl(getProject()).fireModuleRenamedByVfsEvent(ModuleImpl.this); } } + + private void setModuleFilePath(String moduleFilePath, String newFilePath) { + ClasspathStorage.modulePathChanged(ModuleImpl.this, newFilePath); + + final ModifiableModuleModel modifiableModel = ModuleManagerImpl.getInstanceImpl(getProject()).getModifiableModel(); + modifiableModel.setModuleFilePath(ModuleImpl.this, moduleFilePath, newFilePath); + modifiableModel.commit(); + + getStateStore().setModuleFilePath(newFilePath); + } + + @Override + public void fileMoved(VirtualFileMoveEvent event) { + final VirtualFile oldParent = event.getOldParent(); + final VirtualFile newParent = event.getNewParent(); + final String dirName = event.getFileName(); + final String ancestorPath = oldParent.getPath() + "/" + dirName; + final String moduleFilePath = getModuleFilePath(); + if (VfsUtil.isAncestor(new File(ancestorPath), new File(moduleFilePath), true)) { + final String relativePath = FileUtil.getRelativePath(ancestorPath, moduleFilePath, '/'); + setModuleFilePath(moduleFilePath, newParent.getPath() + "/" + dirName + "/" + relativePath); + } + } } protected MutablePicoContainer createPicoContainer() { diff --git a/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java b/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java index 9cec66af96d5..4c7b91dcb961 100644 --- a/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java @@ -919,6 +919,12 @@ public class ModuleManagerImpl extends ModuleManager implements ProjectComponent myModuleGroupPath.put(module, groupPath); } } + + @Override + public void setModuleFilePath(Module module, String oldPath, String newFilePath) { + myPathToModule.remove(oldPath); + myPathToModule.put(newFilePath, module); + } } private void commitModel(final ModuleModelImpl moduleModel, final Runnable runnable) { diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/impl/storage/ClasspathStorage.java b/platform/lang-impl/src/com/intellij/openapi/roots/impl/storage/ClasspathStorage.java index 934b00982e0b..e4c70d8f3651 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/impl/storage/ClasspathStorage.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/storage/ClasspathStorage.java @@ -328,6 +328,10 @@ public class ClasspathStorage implements StateStorage { getProvider(getStorageType(module)).moduleRenamed(module, newName); } + public static void modulePathChanged(Module module, String path) { + getProvider(getStorageType(module)).modulePathChanged(module, path); + } + private static class DefaultStorageProvider implements ClasspathStorageProvider { @NonNls public String getID() { @@ -356,6 +360,10 @@ public class ClasspathStorage implements StateStorage { public String getContentRoot(ModifiableRootModel model) { return null; } + + @Override + public void modulePathChanged(Module module, String path) { + } } public static class UnsupportedStorageProvider implements ClasspathStorageProvider { @@ -406,5 +414,10 @@ public class ClasspathStorage implements StateStorage { public String getContentRoot(ModifiableRootModel model) { return null; } + + @Override + public void modulePathChanged(Module module, String path) { + throw new UnsupportedOperationException(getDescription()); + } } } diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/impl/storage/ClasspathStorageProvider.java b/platform/lang-impl/src/com/intellij/openapi/roots/impl/storage/ClasspathStorageProvider.java index 66ef390a49d0..20935866199b 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/impl/storage/ClasspathStorageProvider.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/storage/ClasspathStorageProvider.java @@ -53,6 +53,8 @@ public interface ClasspathStorageProvider { String getContentRoot(ModifiableRootModel model); + void modulePathChanged(Module module, String path); + interface ClasspathConverter { FileSet getFileSet(); diff --git a/plugins/eclipse/src/org/jetbrains/idea/eclipse/config/EclipseClasspathStorageProvider.java b/plugins/eclipse/src/org/jetbrains/idea/eclipse/config/EclipseClasspathStorageProvider.java index 6a26285225b3..28471448c01d 100644 --- a/plugins/eclipse/src/org/jetbrains/idea/eclipse/config/EclipseClasspathStorageProvider.java +++ b/plugins/eclipse/src/org/jetbrains/idea/eclipse/config/EclipseClasspathStorageProvider.java @@ -103,6 +103,14 @@ public class EclipseClasspathStorageProvider implements ClasspathStorageProvider return model.getContentRoots()[0].getPath(); } + @Override + public void modulePathChanged(Module module, String path) { + final EclipseModuleManager moduleManager = EclipseModuleManager.getInstance(module); + if (moduleManager != null) { + moduleManager.setDocumentSet(null); + } + } + public static void registerFiles(final CachedXmlDocumentSet fileCache, final Module module, final String moduleRoot, final String storageRoot) { fileCache.register(EclipseXml.CLASSPATH_FILE, storageRoot); fileCache.register(EclipseXml.PROJECT_FILE, storageRoot); From e0b4c0a1ad0ad26527505e2e669dda1cf81aa7f4 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 2 Feb 2012 16:43:00 +0400 Subject: [PATCH 05/43] undo/redo module renaming (IDEA-59715) --- .../projectView/impl/RenameModuleHandler.java | 54 ++++++++++++++----- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/RenameModuleHandler.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/RenameModuleHandler.java index 98e956b9f60c..2ec203bf6131 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/RenameModuleHandler.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/RenameModuleHandler.java @@ -22,6 +22,10 @@ import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.actionSystem.LangDataKeys; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.CommandProcessor; +import com.intellij.openapi.command.undo.BasicUndoableAction; +import com.intellij.openapi.command.undo.UndoManager; +import com.intellij.openapi.command.undo.UndoableAction; +import com.intellij.openapi.command.undo.UnexpectedUndoException; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.module.ModifiableModuleModel; @@ -37,6 +41,7 @@ import com.intellij.psi.PsiFile; import com.intellij.refactoring.RefactoringBundle; import com.intellij.refactoring.rename.RenameHandler; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * @author dsl @@ -86,6 +91,41 @@ public class RenameModuleHandler implements RenameHandler, TitledHandler { } public boolean canClose(final String inputString) { + final String oldName = myModule.getName(); + final ModifiableModuleModel modifiableModel = renameModule(inputString); + if (modifiableModel == null) return false; + final Ref success = Ref.create(Boolean.TRUE); + CommandProcessor.getInstance().executeCommand(myProject, new Runnable() { + public void run() { + UndoableAction action = new BasicUndoableAction() { + public void undo() throws UnexpectedUndoException { + final ModifiableModuleModel modifiableModel = renameModule(oldName); + if (modifiableModel != null) { + modifiableModel.commit(); + } + } + + @Override + public void redo() throws UnexpectedUndoException { + final ModifiableModuleModel modifiableModel = renameModule(inputString); + if (modifiableModel != null) { + modifiableModel.commit(); + } + } + }; + UndoManager.getInstance(myProject).undoableActionPerformed(action); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + public void run() { + modifiableModel.commit(); + } + }); + } + }, IdeBundle.message("command.renaming.module", oldName), null); + return success.get().booleanValue(); + } + + @Nullable + private ModifiableModuleModel renameModule(String inputString) { final ModifiableModuleModel modifiableModel = ModuleManager.getInstance(myProject).getModifiableModel(); try { modifiableModel.renameModule(myModule, inputString); @@ -93,19 +133,9 @@ public class RenameModuleHandler implements RenameHandler, TitledHandler { catch (ModuleWithNameAlreadyExists moduleWithNameAlreadyExists) { Messages.showErrorDialog(myProject, IdeBundle.message("error.module.already.exists", inputString), IdeBundle.message("title.rename.module")); - return false; + return null; } - final Ref success = Ref.create(Boolean.TRUE); - CommandProcessor.getInstance().executeCommand(myProject, new Runnable() { - public void run() { - ApplicationManager.getApplication().runWriteAction(new Runnable() { - public void run() { - modifiableModel.commit(); - } - }); - } - }, IdeBundle.message("command.renaming.module", myModule.getName()), null); - return success.get().booleanValue(); + return modifiableModel; } } From ca18fd19a860e862614fec9d2ebda612d051016c Mon Sep 17 00:00:00 2001 From: Maxim Shafirov Date: Thu, 2 Feb 2012 16:43:47 +0400 Subject: [PATCH 06/43] NPE --- .../com/intellij/openapi/vfs/impl/jar/CoreJarVirtualFile.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/CoreJarVirtualFile.java b/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/CoreJarVirtualFile.java index e5ea5d2d4e68..e0c4af1adc4a 100644 --- a/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/CoreJarVirtualFile.java +++ b/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/CoreJarVirtualFile.java @@ -38,7 +38,9 @@ public class CoreJarVirtualFile extends VirtualFile { myParent = parent; myEntry = entry; - parent.myChildren.add(this); + if (parent != null) { + parent.myChildren.add(this); + } } @NotNull From d4840aafad34e887ee8a168a46c904424229517b Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Thu, 2 Feb 2012 17:05:55 +0400 Subject: [PATCH 07/43] GitMergeUpdater: remove incorrect parameter from 'git reset --merge' --- plugins/git4idea/src/git4idea/update/GitMergeUpdater.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/git4idea/src/git4idea/update/GitMergeUpdater.java b/plugins/git4idea/src/git4idea/update/GitMergeUpdater.java index 7d4f42b7afdf..0cef94988ced 100644 --- a/plugins/git4idea/src/git4idea/update/GitMergeUpdater.java +++ b/plugins/git4idea/src/git4idea/update/GitMergeUpdater.java @@ -189,7 +189,7 @@ public class GitMergeUpdater extends GitUpdater { try { GitSimpleHandler h = new GitSimpleHandler(myProject, myRoot, GitCommand.RESET); h.setNoSSH(true); - h.addParameters("-v", "--merge"); + h.addParameters("--merge"); h.run(); } catch (VcsException e) { LOG.info("cancel git reset --merge", e); From 662274478e9a4c811124ffc4177006bdd540d45c Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Thu, 2 Feb 2012 14:06:33 +0100 Subject: [PATCH 08/43] Removed environment option for ps cmd. --- .../execution/process/UnixProcessManager.java | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/platform/util/src/com/intellij/execution/process/UnixProcessManager.java b/platform/util/src/com/intellij/execution/process/UnixProcessManager.java index 3a695a6f8256..3cc2fe9bbf37 100644 --- a/platform/util/src/com/intellij/execution/process/UnixProcessManager.java +++ b/platform/util/src/com/intellij/execution/process/UnixProcessManager.java @@ -177,23 +177,16 @@ public class UnixProcessManager { psCommand = "ps"; } if (SystemInfo.isLinux) { - return new String[]{psCommand, "-e", "e", "--format", commandLineOnly ? "%a" : "%P%p%a"}; + return new String[]{psCommand, "-e", "--format", commandLineOnly ? "%a" : "%P%p%a"}; } - else if (SystemInfo.isMac) { - return new String[]{psCommand, "-ax", "-E", "-o", commandLineOnly ? "command" : "ppid,pid,command"}; - } - else if (SystemInfo.isFreeBSD) { - return new String[]{psCommand, "-ax", "-e", "-o", commandLineOnly ? "command" : "ppid,pid,command"}; + else if (SystemInfo.isMac || SystemInfo.isFreeBSD) { + return new String[]{psCommand, "-ax", "-o", commandLineOnly ? "command" : "ppid,pid,command"}; } else { throw new IllegalStateException(System.getProperty("os.name") + " is not supported."); } } - public static boolean containsMarker(@NotNull String environ, @NotNull String uid) { - return environ.contains(uid); - } - @NotNull public static String readProcEnviron(int child_pid) throws FileNotFoundException { StringBuffer res = new StringBuffer(); From cddaa1749ecada11622090c978a24f2fa7839e08 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Thu, 2 Feb 2012 17:06:58 +0400 Subject: [PATCH 09/43] Git: if fetch is cancelled, display "cancelled" message instead of "error" --- .../src/git4idea/update/GitFetchResult.java | 5 +++++ .../src/git4idea/update/GitFetcher.java | 21 ++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/plugins/git4idea/src/git4idea/update/GitFetchResult.java b/plugins/git4idea/src/git4idea/update/GitFetchResult.java index 9ad9b231adf4..164992dbb3e3 100644 --- a/plugins/git4idea/src/git4idea/update/GitFetchResult.java +++ b/plugins/git4idea/src/git4idea/update/GitFetchResult.java @@ -45,6 +45,11 @@ public final class GitFetchResult { return new GitFetchResult(Type.SUCCESS); } + @NotNull + public static GitFetchResult cancel() { + return new GitFetchResult(Type.CANCELLED); + } + @NotNull public static GitFetchResult error(Collection errors) { GitFetchResult result = new GitFetchResult(Type.ERROR); diff --git a/plugins/git4idea/src/git4idea/update/GitFetcher.java b/plugins/git4idea/src/git4idea/update/GitFetcher.java index 7682e0736dfb..6073c2d1bfe2 100644 --- a/plugins/git4idea/src/git4idea/update/GitFetcher.java +++ b/plugins/git4idea/src/git4idea/update/GitFetcher.java @@ -33,7 +33,7 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collection; -import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; /** * @author Kirill Likhodedov @@ -75,9 +75,11 @@ public class GitFetcher { result = res; break; } - } else { - if (!fetchNatively(root, remote)) { - result = GitFetchResult.error(myErrors); + } + else { + GitFetchResult fetchResult = fetchNatively(root, remote); + if (!fetchResult.isSuccess()) { + result = fetchResult; break; } } @@ -87,22 +89,24 @@ public class GitFetcher { return result; } - private boolean fetchNatively(@NotNull VirtualFile root, @NotNull GitRemote remote) { + private GitFetchResult fetchNatively(@NotNull VirtualFile root, @NotNull GitRemote remote) { final GitLineHandlerPasswordRequestAware h = new GitLineHandlerPasswordRequestAware(myProject, root, GitCommand.FETCH); h.addParameters(remote.getName()); final GitTask fetchTask = new GitTask(myProject, h, "Fetching..."); fetchTask.setProgressIndicator(myProgressIndicator); fetchTask.setProgressAnalyzer(new GitStandardProgressAnalyzer()); - final AtomicBoolean success = new AtomicBoolean(); + + final AtomicReference result = new AtomicReference(); fetchTask.execute(true, false, new GitTaskResultHandlerAdapter() { @Override protected void onSuccess() { - success.set(true); + result.set(GitFetchResult.success()); } @Override protected void onCancel() { LOG.info("Cancelled fetch."); + result.set(GitFetchResult.cancel()); } @Override @@ -113,9 +117,10 @@ public class GitFetcher { } else { myErrors.add(new VcsException("Authentication failed")); } + result.set(GitFetchResult.error(myErrors)); } }); - return success.get(); + return result.get(); } @NotNull From d17a4af5bc8e63312234b4524a4088fab3fe030a Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Thu, 2 Feb 2012 17:08:15 +0400 Subject: [PATCH 10/43] Git: remove RunnerMediator usage: OSProcessManager.killProcessTree is used by OSProcessHandler by default --- .../src/git4idea/commands/GitTextHandler.java | 39 ++----------------- .../git4idea/config/GitVersionSpecialty.java | 7 ---- 2 files changed, 4 insertions(+), 42 deletions(-) diff --git a/plugins/git4idea/src/git4idea/commands/GitTextHandler.java b/plugins/git4idea/src/git4idea/commands/GitTextHandler.java index 22838705a3e9..9a3f63289471 100644 --- a/plugins/git4idea/src/git4idea/commands/GitTextHandler.java +++ b/plugins/git4idea/src/git4idea/commands/GitTextHandler.java @@ -22,7 +22,6 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Key; import com.intellij.openapi.vfs.VirtualFile; -import git4idea.config.GitVersionSpecialty; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -54,7 +53,7 @@ public abstract class GitTextHandler extends GitHandler { if (myIsDestroyed) { return null; } - final ProcessHandler processHandler = new MyRunnerMediator().createProcess(myCommandLine); + final ProcessHandler processHandler = createProcess(myCommandLine); myHandler = (OSProcessHandler)processHandler; return myHandler.getProcess(); } @@ -118,32 +117,9 @@ public abstract class GitTextHandler extends GitHandler { } } - /** - * RunnerMediator that attaches our MyProcessHandler to the process instead of the standard CustomDestroyProcessHandler. - */ - private class MyRunnerMediator extends RunnerMediator { - private boolean canUseRunnerMediator; - - MyRunnerMediator() { - canUseRunnerMediator = !GitVersionSpecialty.DOESNT_GET_PARAMETERS_FROM_RUNNERW.existsIn(myVcs.getVersion()); - } - - @Override - public ProcessHandler createProcess(@NotNull GeneralCommandLine commandLine) throws ExecutionException { - if (!canUseRunnerMediator) { - // not injecting runnerw in case of cygwin, because runnerw doesn't pass parameters to cygwin git. - // the reason of this is under investigation, until then we're running cygwin git directly. - Process process = commandLine.createProcess(); - return createProcessHandler(process, commandLine); - } else { - return super.createProcess(commandLine); - } - } - - @Override - protected ProcessHandler createProcessHandler(@NotNull Process process, @NotNull GeneralCommandLine commandLine) { - return new MyOSProcessHandler(process, commandLine, getCharset()); - } + public ProcessHandler createProcess(@NotNull GeneralCommandLine commandLine) throws ExecutionException { + Process process = commandLine.createProcess(); + return new MyOSProcessHandler(process, commandLine, getCharset()); } private static class MyOSProcessHandler extends OSProcessHandler { @@ -159,13 +135,6 @@ public abstract class GitTextHandler extends GitHandler { Charset charset = myCharset; return charset == null ? super.getCharset() : charset; } - - @Override - protected void destroyProcessImpl() { - if (!RunnerMediator.destroyProcess(getProcess())) { - super.destroyProcessImpl(); - } - } } } diff --git a/plugins/git4idea/src/git4idea/config/GitVersionSpecialty.java b/plugins/git4idea/src/git4idea/config/GitVersionSpecialty.java index cc3d67b84809..c5104f9fb9ab 100644 --- a/plugins/git4idea/src/git4idea/config/GitVersionSpecialty.java +++ b/plugins/git4idea/src/git4idea/config/GitVersionSpecialty.java @@ -48,13 +48,6 @@ public enum GitVersionSpecialty { } }, - DOESNT_GET_PARAMETERS_FROM_RUNNERW { - @Override - public boolean existsIn(@NotNull GitVersion version) { - return version.getType().equals(GitVersion.Type.CYGWIN); - } - }, - NEEDS_QUOTES_IN_STASH_NAME { @Override public boolean existsIn(@NotNull GitVersion version) { From f3ab3b8aebdad6e9403452364ced5a86c0de2a8f Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Thu, 2 Feb 2012 14:08:51 +0100 Subject: [PATCH 11/43] StringBuffer->StringBuilder. --- .../src/com/intellij/execution/process/UnixProcessManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/util/src/com/intellij/execution/process/UnixProcessManager.java b/platform/util/src/com/intellij/execution/process/UnixProcessManager.java index 3cc2fe9bbf37..73b60845b61e 100644 --- a/platform/util/src/com/intellij/execution/process/UnixProcessManager.java +++ b/platform/util/src/com/intellij/execution/process/UnixProcessManager.java @@ -152,7 +152,7 @@ public class UnixProcessManager { result = false; } - StringBuffer errorStr = new StringBuffer(); + StringBuilder errorStr = new StringBuilder(); while ((s = stdError.readLine()) != null) { errorStr.append(s).append("\n"); } From 53f7a92523ee68764d33a4e320192ce59ae845c6 Mon Sep 17 00:00:00 2001 From: Dennis Ushakov Date: Thu, 2 Feb 2012 15:15:15 +0400 Subject: [PATCH 12/43] toolbars are gone from debugger views, console and log can live with horizontal --- .../src/com/intellij/execution/ui/layout/impl/RunnerLayout.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/execution/ui/layout/impl/RunnerLayout.java b/platform/lang-impl/src/com/intellij/execution/ui/layout/impl/RunnerLayout.java index 851d3a42944c..2f6dbc88635c 100644 --- a/platform/lang-impl/src/com/intellij/execution/ui/layout/impl/RunnerLayout.java +++ b/platform/lang-impl/src/com/intellij/execution/ui/layout/impl/RunnerLayout.java @@ -174,7 +174,7 @@ public class RunnerLayout { } public boolean isToolbarHorizontal() { - return myGeneral.horizontalToolbar; + return false; } public void setToolbarHorizontal(boolean horizontal) { From 472660fb6975be9e1fd1430b1505985732fa09a5 Mon Sep 17 00:00:00 2001 From: Dennis Ushakov Date: Thu, 2 Feb 2012 16:09:18 +0400 Subject: [PATCH 13/43] EA-33421 --- .../ui/layout/impl/RunnerContentUi.java | 21 +++++++++++++++++++ .../ui/layout/impl/RunnerLayoutUiImpl.java | 6 +++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/execution/ui/layout/impl/RunnerContentUi.java b/platform/lang-impl/src/com/intellij/execution/ui/layout/impl/RunnerContentUi.java index f256405b29e1..b7d0331a9517 100644 --- a/platform/lang-impl/src/com/intellij/execution/ui/layout/impl/RunnerContentUi.java +++ b/platform/lang-impl/src/com/intellij/execution/ui/layout/impl/RunnerContentUi.java @@ -695,6 +695,27 @@ public class RunnerContentUi implements ContentUI, Disposable, CellTransform.Fac return (ActionGroup)myActionManager.getAction(SETTINGS); } + public ContentManager getContentManager(Content content) { + if (hasContent(myManager, content)) { + return myManager; + } + for (RunnerContentUi child : myChildren) { + if (hasContent(child.myManager, content)) { + return child.myManager; + } + } + return myManager; + } + + private static boolean hasContent(ContentManager manager, Content content) { + for (Content c : manager.getContents()) { + if (c == content) { + return true; + } + } + return false; + } + private static void moveFollowingTabs(int index, final JBRunnerTabs tabs) { for (TabInfo info : tabs.getTabs()) { final TabImpl tab = getTabFor(info); diff --git a/platform/lang-impl/src/com/intellij/execution/ui/layout/impl/RunnerLayoutUiImpl.java b/platform/lang-impl/src/com/intellij/execution/ui/layout/impl/RunnerLayoutUiImpl.java index 584d919fb087..c850e815f0e2 100644 --- a/platform/lang-impl/src/com/intellij/execution/ui/layout/impl/RunnerLayoutUiImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/ui/layout/impl/RunnerLayoutUiImpl.java @@ -169,7 +169,11 @@ public class RunnerLayoutUiImpl implements Disposable, RunnerLayoutUi, LayoutSta public ActionCallback selectAndFocus(@Nullable final Content content, boolean requestFocus, final boolean forced, boolean implicit) { if (content == null) return new ActionCallback.Rejected(); - return getContentManager().setSelectedContent(content, requestFocus || shouldRequestFocus(), forced, implicit); + return getContentManager(content).setSelectedContent(content, requestFocus || shouldRequestFocus(), forced, implicit); + } + + private ContentManager getContentManager(@NotNull Content content) { + return myContentUI.getContentManager(content); } private boolean shouldRequestFocus() { From 536832f507ef99bd484eee60ebdcefa45c4d00e0 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Thu, 2 Feb 2012 14:53:50 +0100 Subject: [PATCH 14/43] fix possible NPEs --- .../ether/dependencyView/Mappings.java | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/jps/model/src/org/jetbrains/ether/dependencyView/Mappings.java b/jps/model/src/org/jetbrains/ether/dependencyView/Mappings.java index c500c9d1b09a..23c124d3c631 100644 --- a/jps/model/src/org/jetbrains/ether/dependencyView/Mappings.java +++ b/jps/model/src/org/jetbrains/ether/dependencyView/Mappings.java @@ -1433,11 +1433,12 @@ public class Mappings { debug("Dependent file: ", depFile); final Collection depClusters = mySourceFileToUsages.get(depFile); - - for (UsageRepr.Cluster depCluster : depClusters) { - final Set depUsages = depCluster.getUsages(); - - if (depUsages != null) { + if (depClusters != null) { + for (UsageRepr.Cluster depCluster : depClusters) { + final Set depUsages = depCluster.getUsages(); + if (depUsages == null) { + continue; + } final Set usages = new HashSet(depUsages); usages.retainAll(affectedUsages); @@ -1512,15 +1513,17 @@ public class Mappings { myClassToSubclasses.removeFrom(superSomething, cr.name); } - for (UsageRepr.Cluster cluster : clusters) { - final Set usages = cluster.getUsages(); - if (usages != null) { - for (UsageRepr.Usage u : usages) { - if (u instanceof UsageRepr.ClassUsage) { - final Set residents = cluster.getResidence(u); + if (clusters != null) { + for (UsageRepr.Cluster cluster : clusters) { + final Set usages = cluster.getUsages(); + if (usages != null) { + for (UsageRepr.Usage u : usages) { + if (u instanceof UsageRepr.ClassUsage) { + final Set residents = cluster.getResidence(u); - if (residents != null && residents.contains(cr.name)) { - myClassToClassDependency.removeFrom(((UsageRepr.ClassUsage)u).className, cr.name); + if (residents != null && residents.contains(cr.name)) { + myClassToClassDependency.removeFrom(((UsageRepr.ClassUsage)u).className, cr.name); + } } } } From 216edb996a870ca4bf071e95dec18efff268913e Mon Sep 17 00:00:00 2001 From: Shaverdova Elena Date: Thu, 2 Feb 2012 17:30:54 +0400 Subject: [PATCH 15/43] WI-8243 File deployment: Sync: Compare by = Timestamp reports files uploaded from project to server as different --- .../platform-api/src/com/intellij/ide/diff/DirDiffSettings.java | 1 + .../vcs-impl/src/com/intellij/openapi/diff/impl/dir/DTree.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/platform/platform-api/src/com/intellij/ide/diff/DirDiffSettings.java b/platform/platform-api/src/com/intellij/ide/diff/DirDiffSettings.java index d37ccdea1c8a..592607973708 100644 --- a/platform/platform-api/src/com/intellij/ide/diff/DirDiffSettings.java +++ b/platform/platform-api/src/com/intellij/ide/diff/DirDiffSettings.java @@ -38,6 +38,7 @@ public class DirDiffSettings { public boolean showNewOnTarget = true; public boolean showCompareModes = true; public CompareMode compareMode = CompareMode.CONTENT; + public double compareTimestampAccuracy = 0; public boolean showInFrame = true; // in dialog otherwise diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DTree.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DTree.java index fc0aadd8898e..55f79ac29eb4 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DTree.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DTree.java @@ -162,7 +162,7 @@ public class DTree { dtype = isEqual(src, trg) ? DType.EQUAL : DType.CHANGED; break; case TIMESTAMP: - dtype = src.getTimeStamp() == trg.getTimeStamp() ? DType.EQUAL : DType.CHANGED; + dtype = Math.abs(src.getTimeStamp() - trg.getTimeStamp()) <= settings.compareTimestampAccuracy ? DType.EQUAL : DType.CHANGED; break; } } From 2b60fe51789b939febe411cde568b08b35e2ad20 Mon Sep 17 00:00:00 2001 From: Maxim Shafirov Date: Thu, 2 Feb 2012 18:09:56 +0400 Subject: [PATCH 16/43] fix double slash in paths --- .../openapi/vfs/impl/jar/CoreJarVirtualFile.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/CoreJarVirtualFile.java b/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/CoreJarVirtualFile.java index e0c4af1adc4a..25286f8b820e 100644 --- a/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/CoreJarVirtualFile.java +++ b/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/CoreJarVirtualFile.java @@ -58,7 +58,15 @@ public class CoreJarVirtualFile extends VirtualFile { @Override public String getPath() { if (myParent == null) return myHandler.myBasePath + "!/"; - return myParent.getPath() + "/" + myEntry.shortName; + + String parentPath = myParent.getPath(); + StringBuilder answer = new StringBuilder(parentPath.length() + 1 + myEntry.shortName.length()); + if (answer.charAt(answer.length() - 1) != '/') { + answer.append('/'); + } + answer.append(myEntry.shortName); + + return answer.toString(); } @Override From 000342e1b5f01d1898b80a6689d98eea38ed85ee Mon Sep 17 00:00:00 2001 From: Maxim Shafirov Date: Thu, 2 Feb 2012 18:34:04 +0400 Subject: [PATCH 17/43] fix double slash in paths --- .../com/intellij/openapi/vfs/impl/jar/CoreJarVirtualFile.java | 1 + 1 file changed, 1 insertion(+) diff --git a/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/CoreJarVirtualFile.java b/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/CoreJarVirtualFile.java index 25286f8b820e..3827ecc2da66 100644 --- a/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/CoreJarVirtualFile.java +++ b/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/CoreJarVirtualFile.java @@ -61,6 +61,7 @@ public class CoreJarVirtualFile extends VirtualFile { String parentPath = myParent.getPath(); StringBuilder answer = new StringBuilder(parentPath.length() + 1 + myEntry.shortName.length()); + answer.append(parentPath); if (answer.charAt(answer.length() - 1) != '/') { answer.append('/'); } From 08c20b63e0a2b701eb6a041e6ed43c343a049b80 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 2 Feb 2012 18:37:28 +0400 Subject: [PATCH 18/43] junit: avoid start via old junit3 starter (IDEA-80728) vm option: idea.force.junit3 --- .../intellij/execution/junit/TestClass.java | 12 +++---- .../intellij/execution/junit/TestMethod.java | 21 ------------ .../intellij/execution/junit/TestMethods.java | 17 ---------- .../intellij/execution/junit/TestObject.java | 1 - .../com/intellij/junit3/TestRunnerUtil.java | 1 - .../intellij/junit4/JUnit4TestRunnerUtil.java | 6 ---- .../rt/execution/junit/JUnitStarter.java | 32 ++++--------------- 7 files changed, 10 insertions(+), 80 deletions(-) diff --git a/plugins/junit/src/com/intellij/execution/junit/TestClass.java b/plugins/junit/src/com/intellij/execution/junit/TestClass.java index 25acd5c5fa45..5fe8a2b08b87 100644 --- a/plugins/junit/src/com/intellij/execution/junit/TestClass.java +++ b/plugins/junit/src/com/intellij/execution/junit/TestClass.java @@ -16,7 +16,10 @@ package com.intellij.execution.junit; -import com.intellij.execution.*; +import com.intellij.execution.ExecutionBundle; +import com.intellij.execution.ExecutionException; +import com.intellij.execution.JavaExecutionUtil; +import com.intellij.execution.ProgramRunnerUtil; import com.intellij.execution.configurations.*; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Comparing; @@ -24,9 +27,7 @@ import com.intellij.psi.PsiClass; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiMethod; import com.intellij.psi.PsiPackage; -import com.intellij.psi.search.GlobalSearchScope; import com.intellij.refactoring.listeners.RefactoringElementListener; -import com.intellij.rt.execution.junit.JUnitStarter; class TestClass extends TestObject { public TestClass(final Project project, @@ -41,11 +42,6 @@ class TestClass extends TestObject { final JUnitConfiguration.Data data = myConfiguration.getPersistentData(); RunConfigurationModule module = myConfiguration.getConfigurationModule(); configureModule(myJavaParameters, module, data.getMainClassName()); - final Project project = module.getProject(); - final PsiClass psiClass = JavaExecutionUtil.findMainClass(project, data.getMainClassName(), GlobalSearchScope.allScope(project)); - if (JUnitUtil.isJUnit4TestClass(psiClass)) { - myJavaParameters.getProgramParametersList().add(JUnitStarter.JUNIT4_PARAMETER); - } myJavaParameters.getProgramParametersList().add(data.getMainClassName()); } diff --git a/plugins/junit/src/com/intellij/execution/junit/TestMethod.java b/plugins/junit/src/com/intellij/execution/junit/TestMethod.java index e84c0ff0bc7a..8ad7f6245043 100644 --- a/plugins/junit/src/com/intellij/execution/junit/TestMethod.java +++ b/plugins/junit/src/com/intellij/execution/junit/TestMethod.java @@ -25,11 +25,9 @@ import com.intellij.psi.PsiClass; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiMethod; import com.intellij.psi.PsiPackage; -import com.intellij.psi.search.GlobalSearchScope; import com.intellij.refactoring.listeners.RefactoringElementAdapter; import com.intellij.refactoring.listeners.RefactoringElementListener; import com.intellij.refactoring.listeners.UndoRefactoringElementListener; -import com.intellij.rt.execution.junit.JUnitStarter; import org.jetbrains.annotations.NotNull; class TestMethod extends TestObject { @@ -45,8 +43,6 @@ class TestMethod extends TestObject { final JUnitConfiguration.Data data = myConfiguration.getPersistentData(); RunConfigurationModule module = myConfiguration.getConfigurationModule(); configureModule(getJavaParameters(), module, data.getMainClassName()); - addJUnit4Parameter(data, module.getProject()); - getJavaParameters().getProgramParametersList().add(data.getMainClassName() + "," + data.getMethodName()); } @@ -54,23 +50,6 @@ class TestMethod extends TestObject { super.initialize(); } - protected void addJUnit4Parameter(final JUnitConfiguration.Data data, Project project) { - final PsiClass psiClass = JavaExecutionUtil.findMainClass(project, data.getMainClassName(), GlobalSearchScope.allScope(project)); - LOG.assertTrue(psiClass != null); - if (JUnitUtil.isJUnit4TestClass(psiClass)) { - myJavaParameters.getProgramParametersList().add(JUnitStarter.JUNIT4_PARAMETER); - return; - } - final String methodName = data.getMethodName(); - PsiMethod[] methods = psiClass.findMethodsByName(methodName, true); - for (PsiMethod method : methods) { - if (JUnitUtil.isTestAnnotated(method)) { - myJavaParameters.getProgramParametersList().add(JUnitStarter.JUNIT4_PARAMETER); - break; - } - } - } - public String suggestActionName() { return ProgramRunnerUtil.shortenName(myConfiguration.getPersistentData().METHOD_NAME, 2) + "()"; } diff --git a/plugins/junit/src/com/intellij/execution/junit/TestMethods.java b/plugins/junit/src/com/intellij/execution/junit/TestMethods.java index 46610b5decb1..14fe7cb6cbcf 100644 --- a/plugins/junit/src/com/intellij/execution/junit/TestMethods.java +++ b/plugins/junit/src/com/intellij/execution/junit/TestMethods.java @@ -33,7 +33,6 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiMethod; -import com.intellij.rt.execution.junit.JUnitStarter; import com.intellij.util.Function; import java.util.Collection; @@ -58,7 +57,6 @@ public class TestMethods extends TestMethod { final JUnitConfiguration.Data data = myConfiguration.getPersistentData(); RunConfigurationModule module = myConfiguration.getConfigurationModule(); final Project project = module.getProject(); - addJUnit4Parameter(data, project); final ExecutionException[] exception = new ExecutionException[1]; ApplicationManager.getApplication().runReadAction(new Runnable() { public void run() { @@ -92,21 +90,6 @@ public class TestMethods extends TestMethod { }, data.getPackageName(), true, false); } - protected void addJUnit4Parameter(final JUnitConfiguration.Data data, Project project) { - for (AbstractTestProxy failedTest : myFailedTests) { - Location location = failedTest.getLocation(project); - if (!(location instanceof MethodLocation)) continue; - if (JUnitUtil.isJUnit4TestClass(((MethodLocation)location).getContainingClass())) { - myJavaParameters.getProgramParametersList().add(JUnitStarter.JUNIT4_PARAMETER); - return; - } - PsiMethod method = ((MethodLocation)location).getPsiElement(); - if (JUnitUtil.isTestAnnotated(method)) { - myJavaParameters.getProgramParametersList().add(JUnitStarter.JUNIT4_PARAMETER); - return; - } - } - } public String suggestActionName() { return ActionsBundle.message("action.RerunFailedTests.text"); diff --git a/plugins/junit/src/com/intellij/execution/junit/TestObject.java b/plugins/junit/src/com/intellij/execution/junit/TestObject.java index b3a288099cb6..c8ba4cafcc8a 100644 --- a/plugins/junit/src/com/intellij/execution/junit/TestObject.java +++ b/plugins/junit/src/com/intellij/execution/junit/TestObject.java @@ -399,7 +399,6 @@ public abstract class TestObject implements JavaCommandLine { final PrintWriter writer = new PrintWriter(myTempFile, "UTF-8"); try { - writer.println(junit4 ? JUnitStarter.JUNIT4_PARAMETER : "-junit3"); writer.println(packageName); final List testNames = new ArrayList(); for (final T element : elements) { diff --git a/plugins/junit_rt/src/com/intellij/junit3/TestRunnerUtil.java b/plugins/junit_rt/src/com/intellij/junit3/TestRunnerUtil.java index db09301dbab4..e6b94fb176b8 100644 --- a/plugins/junit_rt/src/com/intellij/junit3/TestRunnerUtil.java +++ b/plugins/junit_rt/src/com/intellij/junit3/TestRunnerUtil.java @@ -51,7 +51,6 @@ public class TestRunnerUtil { BufferedReader reader = new BufferedReader(new FileReader(suiteClassName.substring(1))); Vector vector; try { - reader.readLine(); //skip junit4/junit3 parameter suiteName = reader.readLine(); vector = new Vector(); String line; diff --git a/plugins/junit_rt/src/com/intellij/junit4/JUnit4TestRunnerUtil.java b/plugins/junit_rt/src/com/intellij/junit4/JUnit4TestRunnerUtil.java index 95cf1181ab5d..75a4d4d32af7 100644 --- a/plugins/junit_rt/src/com/intellij/junit4/JUnit4TestRunnerUtil.java +++ b/plugins/junit_rt/src/com/intellij/junit4/JUnit4TestRunnerUtil.java @@ -17,8 +17,6 @@ package com.intellij.junit4; import org.junit.Ignore; import org.junit.internal.AssumptionViolatedException; -import org.junit.internal.builders.AllDefaultPossibilitiesBuilder; -import org.junit.internal.builders.AnnotatedBuilder; import org.junit.internal.requests.ClassRequest; import org.junit.internal.runners.model.EachTestNotifier; import org.junit.runner.Description; @@ -29,14 +27,11 @@ import org.junit.runner.manipulation.Filter; import org.junit.runner.notification.RunNotifier; import org.junit.runners.BlockJUnit4ClassRunner; import org.junit.runners.Parameterized; -import org.junit.runners.ParentRunner; import org.junit.runners.model.FrameworkMethod; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; -import java.lang.annotation.Annotation; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.text.MessageFormat; import java.util.*; @@ -60,7 +55,6 @@ public class JUnit4TestRunnerUtil { final Map classMethods = new HashMap(); BufferedReader reader = new BufferedReader(new FileReader(suiteClassName.substring(1))); try { - reader.readLine(); //skip junit4/junit3 parameter final String packageName = reader.readLine(); String line; diff --git a/plugins/junit_rt/src/com/intellij/rt/execution/junit/JUnitStarter.java b/plugins/junit_rt/src/com/intellij/rt/execution/junit/JUnitStarter.java index f492409c9e18..376f1e749890 100644 --- a/plugins/junit_rt/src/com/intellij/rt/execution/junit/JUnitStarter.java +++ b/plugins/junit_rt/src/com/intellij/rt/execution/junit/JUnitStarter.java @@ -32,7 +32,6 @@ import java.util.Vector; public class JUnitStarter { public static final int VERSION = 5; public static final String IDE_VERSION = "-ideVersion"; - public static final String JUNIT4_PARAMETER = "-junit4"; private static final String SOCKET = "-socket"; private static String ourForkMode; private static String ourCommandFileName; @@ -65,17 +64,12 @@ public class JUnitStarter { } private static boolean processParameters(Vector args, final List listeners) { - boolean isJunit4 = false; - String tempFilePath = null; Vector result = new Vector(args.size()); for (int i = 0; i < args.size(); i++) { String arg = (String)args.get(i); if (arg.startsWith(IDE_VERSION)) { //ignore } - else if (arg.equals(JUNIT4_PARAMETER)){ - isJunit4 = true; - } else { if (arg.startsWith("@@@")) { final int pos = arg.indexOf(','); @@ -96,8 +90,6 @@ public class JUnitStarter { } } continue; - } else if (arg.startsWith("@")) { - tempFilePath = arg.substring(1); } else if (arg.startsWith(SOCKET)) { final int port = Integer.parseInt(arg.substring(SOCKET.length())); try { @@ -114,37 +106,25 @@ public class JUnitStarter { e.printStackTrace(); } - isJunit4 = isJUnit4(isJunit4, tempFilePath); continue; } result.addElement(arg); } } - if (tempFilePath != null && !args.contains(SOCKET)) { - isJunit4 = isJUnit4(isJunit4, tempFilePath); - } args.removeAllElements(); for (int i = 0; i < result.size(); i++) { String arg = (String)result.get(i); args.addElement(arg); } - return isJunit4; - } - - private static boolean isJUnit4(boolean junit4, String tempFilePath) { + final String forceJUnit3 = System.getProperty("idea.force.junit3"); + if (forceJUnit3 != null && Boolean.valueOf(forceJUnit3).booleanValue()) return false; try { - BufferedReader reader = new BufferedReader(new FileReader(tempFilePath)); - try { - junit4 |= JUNIT4_PARAMETER.equals(reader.readLine()); - } - finally { - reader.close(); - } + Class.forName("org.junit.Test"); + return true; } - catch (IOException e) { - e.printStackTrace(); + catch (ClassNotFoundException e) { + return false; } - return junit4; } public static boolean checkVersion(String[] args, SegmentedOutputStream notifications) { From 317f93f980911b229ef4472f9ca948633119c93a Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 2 Feb 2012 14:06:14 +0100 Subject: [PATCH 19/43] less spam in compile server javac progress messages --- .../src/org/jetbrains/jps/incremental/IncProjectBuilder.java | 2 ++ .../src/org/jetbrains/jps/incremental/java/JavaBuilder.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java index 11ef36a2f3f1..7ddfdc33a493 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java @@ -166,6 +166,8 @@ public class IncProjectBuilder { context.processMessage(new ProgressMessage("Running 'after' tasks")); runTasks(context, myBuilderRegistry.getAfterTasks()); + + context.processMessage(new ProgressMessage("Finished, saving caches...")); } private CompileContext createContext(CompileScope scope, boolean isMake, final boolean isProjectRebuild) throws ProjectBuildException { diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java index 9383724a555e..152a5fca45e1 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java @@ -727,7 +727,7 @@ public class JavaBuilder extends ModuleLevelBuilder { myContext.processMessage(new ProgressMessage("Parsing sources...")); } else { - if (!message.startsWith("total")) { + if (!message.startsWith("total ") && !message.startsWith("loading ") && !message.startsWith("wrote ")) { myContext.processMessage(new ProgressMessage(FileUtil.toSystemDependentName(message))); } } From f96cf9acfd614b1352900a50e4be357354379191 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 2 Feb 2012 14:49:25 +0100 Subject: [PATCH 20/43] IDEA-80749 Make it possible to enable live templates for specific language in custom language plugin --- .../template/impl/LiveTemplateCompletionContributor.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/LiveTemplateCompletionContributor.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/LiveTemplateCompletionContributor.java index 8679d726deb0..6c1bc1123a2b 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/LiveTemplateCompletionContributor.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/LiveTemplateCompletionContributor.java @@ -47,7 +47,7 @@ public class LiveTemplateCompletionContributor extends CompletionContributor { final PsiFile file = parameters.getPosition().getContainingFile(); final int offset = parameters.getOffset(); final List templates = listApplicableTemplates(file, offset); - if (Registry.is("show.live.templates.in.completion")) { + if (showAllTemplates()) { final Ref templatesShown = Ref.create(false); result.runRemainingContributors(parameters, new Consumer() { @@ -78,6 +78,11 @@ public class LiveTemplateCompletionContributor extends CompletionContributor { }); } + @SuppressWarnings("MethodMayBeStatic") //for Kotlin + protected boolean showAllTemplates() { + return Registry.is("show.live.templates.in.completion"); + } + private static void ensureTemplatesShown(Ref templatesShown, List templates, CompletionResultSet result) { if (!templatesShown.get()) { templatesShown.set(true); From 42cf895280c51d5531f1a3a4dd9fe566dad50a83 Mon Sep 17 00:00:00 2001 From: Dennis Ushakov Date: Thu, 2 Feb 2012 18:29:53 +0400 Subject: [PATCH 21/43] IDEA-80706 Debug Tool Window: restore view under Debugger view hides previously restored view --- .../com/intellij/execution/ui/layout/impl/GridCellImpl.java | 3 +-- .../com/intellij/execution/ui/layout/impl/RunnerContentUi.java | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/execution/ui/layout/impl/GridCellImpl.java b/platform/lang-impl/src/com/intellij/execution/ui/layout/impl/GridCellImpl.java index 1350d5fa0468..c85261cd83f8 100644 --- a/platform/lang-impl/src/com/intellij/execution/ui/layout/impl/GridCellImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/ui/layout/impl/GridCellImpl.java @@ -449,9 +449,8 @@ public class GridCellImpl implements GridCell { } } - private ActionCallback restore(Content content) { + ActionCallback restore(Content content) { myMinimizedContents.remove(content); - myContext.getContentManager().addContent(content); return new ActionCallback.Done(); } } diff --git a/platform/lang-impl/src/com/intellij/execution/ui/layout/impl/RunnerContentUi.java b/platform/lang-impl/src/com/intellij/execution/ui/layout/impl/RunnerContentUi.java index b7d0331a9517..81f6cb266d6b 100644 --- a/platform/lang-impl/src/com/intellij/execution/ui/layout/impl/RunnerContentUi.java +++ b/platform/lang-impl/src/com/intellij/execution/ui/layout/impl/RunnerContentUi.java @@ -1326,6 +1326,9 @@ public class RunnerContentUi implements ContentUI, Disposable, CellTransform.Fac final GridImpl grid = getGridFor(content, false); if (grid == null) { getStateFor(content).assignTab(myLayoutSettings.getOrCreateTab(-1)); + } else { + //noinspection ConstantConditions + ((GridCellImpl)findCellFor(content)).restore(content); } getStateFor(content).setMinimizedInGrid(false); myManager.addContent(content); From 3a290433fbf4fc47ecd3e7b5e25950d3c80ec19e Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 2 Feb 2012 16:00:15 +0100 Subject: [PATCH 22/43] understand
as line separator --- .../src/com/intellij/notification/EventLog.java | 11 +++++------ .../com/intellij/notification/EventLogTest.groovy | 6 ++++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/notification/EventLog.java b/platform/platform-impl/src/com/intellij/notification/EventLog.java index 310e5544c0e8..0ba18358cf37 100644 --- a/platform/platform-impl/src/com/intellij/notification/EventLog.java +++ b/platform/platform-impl/src/com/intellij/notification/EventLog.java @@ -46,6 +46,7 @@ import com.intellij.openapi.wm.ToolWindowManager; import com.intellij.ui.awt.RelativePoint; import com.intellij.ui.content.Content; import com.intellij.ui.content.ContentFactory; +import com.intellij.util.containers.CollectionFactory; import com.intellij.util.containers.hash.LinkedHashMap; import com.intellij.util.text.CharArrayUtil; import org.jetbrains.annotations.NonNls; @@ -58,6 +59,7 @@ import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.atomic.AtomicBoolean; import java.util.regex.Matcher; @@ -74,6 +76,7 @@ public class EventLog implements Notifications { private static final String A_CLOSING = ""; private static final Pattern TAG_PATTERN = Pattern.compile("<[^>]*>"); private static final Pattern A_PATTERN = Pattern.compile("]* )?href=[\"\']([^>]*)[\"\'][^>]*>"); + private static final Set NEW_LINES = CollectionFactory.newSet("
", "
", "
", "

", "

", "

"); public EventLog() { ApplicationManager.getApplication().getMessageBus().connect().subscribe(Notifications.TOPIC, this); @@ -188,11 +191,7 @@ public class EventLog implements Notifications { } hasHtml = true; - if ("
".equals(tagStart) || - "
".equals(tagStart) || - "

".equals(tagStart) || - "

".equals(tagStart) || - "

".equals(tagStart)) { + if (NEW_LINES.contains(tagStart)) { lineSeparators.add(document.createRangeMarker(TextRange.from(document.getTextLength(), 0))); } else if (!"".equals(tagStart) && !"".equals(tagStart) && !"".equals(tagStart) && !"".equals(tagStart)) { @@ -219,7 +218,7 @@ public class EventLog implements Notifications { if (offset < document.getTextLength()) { boolean spaceAfter = Character.isWhitespace(document.getCharsSequence().charAt(offset)); int next = CharArrayUtil.shiftForward(document.getCharsSequence(), offset, " \t"); - if (next < document.getTextLength() && Character.isUpperCase(document.getCharsSequence().charAt(next))) { + if (next < document.getTextLength() && !Character.isLowerCase(document.getCharsSequence().charAt(next))) { document.insertString(offset, (spaceBefore ? "" : " ") + "//" + (spaceAfter ? "" : " ")); continue; } diff --git a/platform/platform-tests/testSrc/com/intellij/notification/EventLogTest.groovy b/platform/platform-tests/testSrc/com/intellij/notification/EventLogTest.groovy index e15a4d732592..5c0c049b42a9 100644 --- a/platform/platform-tests/testSrc/com/intellij/notification/EventLogTest.groovy +++ b/platform/platform-tests/testSrc/com/intellij/notification/EventLogTest.groovy @@ -68,4 +68,10 @@ class EventLogTest extends LightPlatformTestCase { assert entry.message == 'link: content (show balloon)' } + public void testVariousNewlines() throws Exception { + assert EventLog.formatForLog(new Notification("xxx", 'title', "foo
bar", NotificationType.ERROR)).message == 'title: foo bar' + assert EventLog.formatForLog(new Notification("xxx", 'title', "foo
/bar", NotificationType.ERROR)).message == 'title: foo // /bar' + assert EventLog.formatForLog(new Notification("xxx", 'title', "foo
Bar", NotificationType.ERROR)).message == 'title: foo // Bar' + } + } From 0e68af47b794d796ec5337b47d9cf6c28d80bcd3 Mon Sep 17 00:00:00 2001 From: Sergey Evdokimov Date: Thu, 2 Feb 2012 19:05:53 +0400 Subject: [PATCH 23/43] Replace ApplicationManager.getApplication().runReadAction() to ApplicationManager.getApplication().acquireReadActionLock(). --- .../MavenSmartCompletionContributor.java | 21 +++++----- .../maven/indices/MavenIndicesManager.java | 16 ++++---- .../maven/project/MavenProjectsManager.java | 13 +++--- .../idea/maven/project/MavenProjectsTree.java | 40 ++++++++++--------- .../idea/maven/utils/MavenJDOMUtil.java | 31 ++++++++------ .../utils/MavenProblemFileHighlighter.java | 16 ++++---- .../maven/wizards/MavenProjectBuilder.java | 32 ++++++++------- .../idea/maven/MavenImportingTestCase.java | 17 ++++---- 8 files changed, 103 insertions(+), 83 deletions(-) diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/model/completion/MavenSmartCompletionContributor.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/model/completion/MavenSmartCompletionContributor.java index 52c2b2616f71..46b3838f9cf9 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/model/completion/MavenSmartCompletionContributor.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/model/completion/MavenSmartCompletionContributor.java @@ -20,12 +20,9 @@ import com.intellij.codeInsight.completion.CompletionContributor; import com.intellij.codeInsight.completion.CompletionParameters; import com.intellij.codeInsight.completion.CompletionResultSet; import com.intellij.codeInsight.completion.CompletionType; -import com.intellij.codeInsight.lookup.LookupElement; -import com.intellij.codeInsight.lookup.LookupElementBuilder; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.util.Computable; import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiNamedElement; import com.intellij.psi.PsiReference; import com.intellij.psi.impl.source.xml.TagNameReference; import com.intellij.psi.xml.XmlText; @@ -46,12 +43,16 @@ public class MavenSmartCompletionContributor extends CompletionContributor { public void fillCompletionVariants(final CompletionParameters parameters, CompletionResultSet result) { if (parameters.getCompletionType() != CompletionType.SMART) return; - Collection variants = ApplicationManager.getApplication().runReadAction(new Computable>() { - @Override - public Collection compute() { - return getVariants(parameters); - } - }); + Collection variants; + + AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock(); + try { + variants = getVariants(parameters); + } + finally { + accessToken.finish(); + } + MavenPropertyCompletionContributor.addVariants(variants, result); } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/indices/MavenIndicesManager.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/indices/MavenIndicesManager.java index 4d06f837f9a1..383ac1124ea9 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/indices/MavenIndicesManager.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/indices/MavenIndicesManager.java @@ -16,6 +16,7 @@ package org.jetbrains.idea.maven.indices; import com.intellij.openapi.Disposable; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.extensions.Extensions; @@ -283,14 +284,15 @@ public class MavenIndicesManager { private static MavenGeneralSettings getMavenSettings(@NotNull final Project project, @NotNull MavenProgressIndicator indicator) throws MavenProcessCanceledException { + MavenGeneralSettings settings; - MavenGeneralSettings settings = ApplicationManager.getApplication().runReadAction(new Computable() { - @Override - public MavenGeneralSettings compute() { - if (project.isDisposed()) return null; - return MavenProjectsManager.getInstance(project).getGeneralSettings(); - } - }); + AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock(); + try { + settings = project.isDisposed() ? null : MavenProjectsManager.getInstance(project).getGeneralSettings(); + } + finally { + accessToken.finish(); + } if (settings == null) { // project was closed diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsManager.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsManager.java index 8ed52326939a..4dfb559d7484 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsManager.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsManager.java @@ -16,6 +16,7 @@ package org.jetbrains.idea.maven.project; import com.intellij.ide.startup.StartupManagerEx; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.PersistentStateComponent; import com.intellij.openapi.components.SettingsSavingComponent; @@ -403,11 +404,13 @@ public class MavenProjectsManager extends MavenSimpleProjectComponent } public boolean isMavenizedModule(final Module m) { - return ApplicationManager.getApplication().runReadAction(new Computable() { - public Boolean compute() { - return "true".equals(m.getOptionValue(getMavenizedModuleOptionName())); - } - }); + AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock(); + try { + return "true".equals(m.getOptionValue(getMavenizedModuleOptionName())); + } + finally { + accessToken.finish(); + } } public void setMavenizedModules(Collection modules, boolean mavenized) { diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsTree.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsTree.java index 7a2b61135328..2cd984935388 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsTree.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsTree.java @@ -15,10 +15,10 @@ */ package org.jetbrains.idea.maven.project; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Comparing; -import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.io.FileUtil; @@ -645,27 +645,29 @@ public class MavenProjectsTree { private MavenProjectTimestamp calculateTimestamp(final MavenProject mavenProject, final Collection explicitProfiles, final MavenGeneralSettings generalSettings) { - return ApplicationManager.getApplication().runReadAction(new Computable() { - public MavenProjectTimestamp compute() { - long pomTimestamp = getFileTimestamp(mavenProject.getFile()); - MavenProject parent = findParent(mavenProject); - long parentLastReadStamp = parent == null ? -1 : parent.getLastReadStamp(); - VirtualFile profilesXmlFile = mavenProject.getProfilesXmlFile(); - long profilesTimestamp = getFileTimestamp(profilesXmlFile); + AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock(); + try { + long pomTimestamp = getFileTimestamp(mavenProject.getFile()); + MavenProject parent = findParent(mavenProject); + long parentLastReadStamp = parent == null ? -1 : parent.getLastReadStamp(); + VirtualFile profilesXmlFile = mavenProject.getProfilesXmlFile(); + long profilesTimestamp = getFileTimestamp(profilesXmlFile); - long userSettingsTimestamp = getFileTimestamp(generalSettings.getEffectiveUserSettingsFile()); - long globalSettingsTimestamp = getFileTimestamp(generalSettings.getEffectiveGlobalSettingsFile()); + long userSettingsTimestamp = getFileTimestamp(generalSettings.getEffectiveUserSettingsFile()); + long globalSettingsTimestamp = getFileTimestamp(generalSettings.getEffectiveGlobalSettingsFile()); - int profilesHashCode = explicitProfiles.hashCode(); + int profilesHashCode = explicitProfiles.hashCode(); - return new MavenProjectTimestamp(pomTimestamp, - parentLastReadStamp, - profilesTimestamp, - userSettingsTimestamp, - globalSettingsTimestamp, - profilesHashCode); - } - }); + return new MavenProjectTimestamp(pomTimestamp, + parentLastReadStamp, + profilesTimestamp, + userSettingsTimestamp, + globalSettingsTimestamp, + profilesHashCode); + } + finally { + accessToken.finish(); + } } private static long getFileTimestamp(VirtualFile file) { diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenJDOMUtil.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenJDOMUtil.java index a7162adf0e72..707fae5105a6 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenJDOMUtil.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenJDOMUtil.java @@ -15,8 +15,8 @@ */ package org.jetbrains.idea.maven.utils; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.JDOMUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.CharsetToolkit; @@ -38,19 +38,24 @@ import static com.intellij.openapi.util.text.StringUtil.isEmptyOrSpaces; public class MavenJDOMUtil { @Nullable public static Element read(final VirtualFile file, @Nullable final ErrorHandler handler) { - String text = ApplicationManager.getApplication().runReadAction(new Computable() { - public String compute() { - if (!file.isValid()) return null; - try { - return VfsUtil.loadText(file); - } - catch (IOException e) { - if (handler != null) handler.onReadError(e); - return null; - } + String text; + + AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock(); + try { + if (!file.isValid()) return null; + + try { + text = VfsUtil.loadText(file); } - }); - if (text == null) return null; + catch (IOException e) { + if (handler != null) handler.onReadError(e); + return null; + } + } + finally { + accessToken.finish(); + } + return doRead(text, handler); } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenProblemFileHighlighter.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenProblemFileHighlighter.java index 49eb62bdcaff..20b2b3293c0b 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenProblemFileHighlighter.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenProblemFileHighlighter.java @@ -15,9 +15,9 @@ */ package org.jetbrains.idea.maven.utils; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.Condition; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; @@ -32,11 +32,13 @@ public class MavenProblemFileHighlighter implements Condition { } public boolean value(final VirtualFile file) { - return ApplicationManager.getApplication().runReadAction(new Computable() { - public Boolean compute() { - PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file); - return psiFile != null && MavenDomUtil.isMavenFile(psiFile); - } - }); + AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock(); + try { + PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file); + return psiFile != null && MavenDomUtil.isMavenFile(psiFile); + } + finally { + accessToken.finish(); + } } } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenProjectBuilder.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenProjectBuilder.java index b531f5382496..613dc2789961 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenProjectBuilder.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenProjectBuilder.java @@ -15,6 +15,7 @@ */ package org.jetbrains.idea.maven.wizards; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.module.ModifiableModuleModel; import com.intellij.openapi.module.Module; @@ -25,7 +26,6 @@ import com.intellij.openapi.projectRoots.JavaSdk; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.roots.ui.configuration.ModulesConfigurator; import com.intellij.openapi.roots.ui.configuration.ModulesProvider; -import com.intellij.openapi.util.Computable; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.packaging.artifacts.ModifiableArtifactModel; @@ -236,24 +236,26 @@ public class MavenProjectBuilder extends ProjectImportBuilder { } private MavenWorkspaceSettings getDirectProjectsSettings() { - return ApplicationManager.getApplication().runReadAction(new Computable() { - @Override - public MavenWorkspaceSettings compute() { - return MavenWorkspaceSettingsComponent.getInstance(getProject()).getState(); - } - }); + AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock(); + try { + return MavenWorkspaceSettingsComponent.getInstance(getProject()).getState(); + } + finally { + accessToken.finish(); + } } @NotNull private Project getProject() { - return ApplicationManager.getApplication().runReadAction(new Computable() { - @Override - public Project compute() { - Project result = isUpdate() ? getProjectToUpdate() : null; - if (result == null || result.isDisposed()) result = ProjectManager.getInstance().getDefaultProject(); - return result; - } - }); + AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock(); + try { + Project result = isUpdate() ? getProjectToUpdate() : null; + if (result == null || result.isDisposed()) result = ProjectManager.getInstance().getDefaultProject(); + return result; + } + finally { + accessToken.finish(); + } } public void setFiles(List files) { diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/MavenImportingTestCase.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/MavenImportingTestCase.java index 8f4550408c9b..13b1770f6776 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/MavenImportingTestCase.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/MavenImportingTestCase.java @@ -20,6 +20,7 @@ import com.intellij.compiler.CompilerManagerImpl; import com.intellij.compiler.CompilerWorkspaceConfiguration; import com.intellij.compiler.impl.ModuleCompileScope; import com.intellij.compiler.impl.TranslatingCompilerFilesMonitor; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.compiler.*; import com.intellij.openapi.module.Module; @@ -291,13 +292,15 @@ public abstract class MavenImportingTestCase extends MavenTestCase { } protected Module getModule(final String name) { - Module m = ApplicationManager.getApplication().runReadAction(new Computable() { - public Module compute() { - return ModuleManager.getInstance(myProject).findModuleByName(name); - } - }); - assertNotNull("Module " + name + " not found", m); - return m; + AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock(); + try { + Module m = ModuleManager.getInstance(myProject).findModuleByName(name); + assertNotNull("Module " + name + " not found", m); + return m; + } + finally { + accessToken.finish(); + } } private ContentEntry getContentRoot(String moduleName) { From 694ff521b470d96f275dd07afba6095710e026ea Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Thu, 2 Feb 2012 19:06:28 +0400 Subject: [PATCH 24/43] PopupFactoryImpl: adjusts icon size to maximum, so that icons with different sizes were aligned correctly in a single action group --- .../intellij/ui/popup/PopupFactoryImpl.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/platform/platform-impl/src/com/intellij/ui/popup/PopupFactoryImpl.java b/platform/platform-impl/src/com/intellij/ui/popup/PopupFactoryImpl.java index be8d54941b07..fd45a822cfa5 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/PopupFactoryImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/PopupFactoryImpl.java @@ -739,6 +739,9 @@ public class PopupFactoryImpl extends JBPopupFactory { icon = actionId != null && actionId.startsWith("QuickList.") ? QUICK_LIST_ICON : myEmptyIcon; } + else { + icon = new IconWrapper(icon); + } boolean prependSeparator = !myListModel.isEmpty() && myPrependWithSeparator; assert text != null : action + " has no presentation"; myListModel.add(new ActionItem(action, text, presentation.isEnabled(), icon, prependSeparator, mySeparatorText)); @@ -747,6 +750,33 @@ public class PopupFactoryImpl extends JBPopupFactory { } } + /** + * Adjusts icon size to maximum, so that icons with different sizes were aligned correctly. + */ + private class IconWrapper implements Icon { + + private Icon myIcon; + + IconWrapper(Icon icon) { + myIcon = icon; + } + + @Override + public void paintIcon(Component c, Graphics g, int x, int y) { + myIcon.paintIcon(c, g, x, y); + } + + @Override + public int getIconWidth() { + return myMaxIconWidth; + } + + @Override + public int getIconHeight() { + return myMaxIconHeight; + } + } + private Presentation getPresentation(@NotNull AnAction action) { Presentation presentation = myAction2presentation.get(action); if (presentation == null) { From d77e31b0d004b9e5ca2c90ccedac86055f05f3ec Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 2 Feb 2012 16:01:30 +0100 Subject: [PATCH 25/43] less duplication in successful push notification --- plugins/git4idea/src/git4idea/push/GitPushResult.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/plugins/git4idea/src/git4idea/push/GitPushResult.java b/plugins/git4idea/src/git4idea/push/GitPushResult.java index 5cb5542a358f..3d327d591431 100644 --- a/plugins/git4idea/src/git4idea/push/GitPushResult.java +++ b/plugins/git4idea/src/git4idea/push/GitPushResult.java @@ -264,11 +264,7 @@ class GitPushResult { notificationType = NotificationType.WARNING; } else { notificationType = NotificationType.INFORMATION; - if (pushedCommitsNumber == 0) { // happens on new branch creation - title = "Pushed successfully"; - } else { - title = "Pushed " + pushedCommitsNumber + " " + StringUtil.pluralize("commit", pushedCommitsNumber); - } + title = "Push successful"; } String errorReport = reportForGroup(groupedResult.myErrorResults, GroupedResult.Type.ERROR); From 8078ea568961a68c04158a80b0bf1f3b8ab274a8 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 2 Feb 2012 16:10:28 +0100 Subject: [PATCH 26/43] correctly place dot when chosen a class name in completion with it --- .../codeInsight/completion/JavaCompletionUtil.java | 2 +- .../codeInsight/completion/normal/ClassNameDot.java | 5 +++++ .../codeInsight/completion/normal/ClassNameDot_after.java | 7 +++++++ .../codeInsight/completion/NormalCompletionTest.groovy | 2 ++ 4 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 java/java-tests/testData/codeInsight/completion/normal/ClassNameDot.java create mode 100644 java/java-tests/testData/codeInsight/completion/normal/ClassNameDot_after.java diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionUtil.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionUtil.java index c081d03ff391..b803bc1d126d 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionUtil.java @@ -740,7 +740,7 @@ public class JavaCompletionUtil { newElement = CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(newElement); if (newElement != null) { newEndOffset = newElement.getTextRange().getEndOffset(); - if (newElement instanceof PsiJavaCodeReferenceElement) { + if (newElement instanceof PsiJavaCodeReferenceElement && !(newElement instanceof PsiReferenceExpression)) { PsiReferenceParameterList parameterList = ((PsiJavaCodeReferenceElement)newElement).getParameterList(); if (parameterList != null) { newEndOffset = parameterList.getTextRange().getStartOffset(); diff --git a/java/java-tests/testData/codeInsight/completion/normal/ClassNameDot.java b/java/java-tests/testData/codeInsight/completion/normal/ClassNameDot.java new file mode 100644 index 000000000000..9646474f789a --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normal/ClassNameDot.java @@ -0,0 +1,5 @@ +class Foo { + { + FIStr + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/normal/ClassNameDot_after.java b/java/java-tests/testData/codeInsight/completion/normal/ClassNameDot_after.java new file mode 100644 index 000000000000..33dc5773ce85 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normal/ClassNameDot_after.java @@ -0,0 +1,7 @@ +import java.io.FileInputStream; + +class Foo { + { + FileInputStream. + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy index e5203e7f1069..4adf38e80a35 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy @@ -1264,4 +1264,6 @@ public class ListUtils { public void testPackageInMemberType() { doTest() } + public void testClassNameDot() { doTest('.') } + } From e1038a5963762ba4db8147a25d5d84a692a86596 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Thu, 2 Feb 2012 16:16:47 +0100 Subject: [PATCH 27/43] find instance by component --- .../src/com/intellij/openapi/ui/ComboBox.java | 14 +------------- .../src/com/intellij/openapi/ui/DialogWrapper.java | 11 +++++++++++ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/platform/platform-api/src/com/intellij/openapi/ui/ComboBox.java b/platform/platform-api/src/com/intellij/openapi/ui/ComboBox.java index 87a7b96aeb3e..b84c801e1b21 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/ComboBox.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/ComboBox.java @@ -197,22 +197,10 @@ public class ComboBox extends ComboBoxWithWidePopup implements AWTEventListener myMinimumAndPreferredWidth = minimumAndPreferredWidth; } - @Nullable - private static DialogWrapperDialog getParentDialog(Component c) { - do { - if (c == null || c instanceof DialogWrapperDialog) { - return (DialogWrapperDialog)c; - } - c = c.getParent(); - } - while (true); - } - private void registerCancelOnEscape() { registerKeyboardAction(new ActionListener() { public void actionPerformed(final ActionEvent e) { - final DialogWrapperDialog dialogWrapperDialog = getParentDialog(ComboBox.this); - final DialogWrapper dialogWrapper = dialogWrapperDialog == null ? null : dialogWrapperDialog.getDialogWrapper(); + final DialogWrapper dialogWrapper = DialogWrapper.findInstance(ComboBox.this); if (isPopupVisible()) { setPopupVisible(false); diff --git a/platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java b/platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java index ccd09e11ce14..093a628d51a7 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java @@ -1573,6 +1573,17 @@ public abstract class DialogWrapper { }, 300, null); } + @Nullable + public static DialogWrapper findInstance(Component c) { + while (c != null){ + if (c instanceof DialogWrapperDialog) { + return ((DialogWrapperDialog)c).getDialogWrapper(); + } + c = c.getParent(); + } + return null; + } + private void updateHeightForErrorText() { if (getRootPane() == null) return; From 35d7691eb896da29ed48a043e2613b86c0886468 Mon Sep 17 00:00:00 2001 From: Sergey Evdokimov Date: Thu, 2 Feb 2012 19:31:24 +0400 Subject: [PATCH 28/43] Replace ApplicationManager.getApplication().runWriteAction() to ApplicationManager.getApplication().acquireWriteActionLock(). --- .../MavenSmartCompletionContributor.java | 10 +--- .../maven/importing/MavenFoldersImporter.java | 46 ++++++++++--------- ...ectsProcessorArtifactsDownloadingTask.java | 15 +++--- .../utils/MavenEnvironmentRegistrar.java | 16 ++++--- .../idea/maven/utils/MavenRehighlighter.java | 16 ++++--- .../library/RepositoryAttachHandler.java | 26 ++++++----- .../importing/DependenciesImportingTest.java | 14 ++++-- 7 files changed, 77 insertions(+), 66 deletions(-) diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/model/completion/MavenSmartCompletionContributor.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/model/completion/MavenSmartCompletionContributor.java index 46b3838f9cf9..e4b1c51c854b 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/model/completion/MavenSmartCompletionContributor.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/model/completion/MavenSmartCompletionContributor.java @@ -43,15 +43,7 @@ public class MavenSmartCompletionContributor extends CompletionContributor { public void fillCompletionVariants(final CompletionParameters parameters, CompletionResultSet result) { if (parameters.getCompletionType() != CompletionType.SMART) return; - Collection variants; - - AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock(); - try { - variants = getVariants(parameters); - } - finally { - accessToken.finish(); - } + Collection variants = getVariants(parameters); MavenPropertyCompletionContributor.addVariants(variants, result); } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/MavenFoldersImporter.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/MavenFoldersImporter.java index 8a8073d2d34d..2cf3f3aed5bc 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/MavenFoldersImporter.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/MavenFoldersImporter.java @@ -15,7 +15,8 @@ */ package org.jetbrains.idea.maven.importing; -import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.AccessToken; +import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; import com.intellij.openapi.project.Project; @@ -29,7 +30,6 @@ import org.jetbrains.idea.maven.project.MavenImportingSettings; import org.jetbrains.idea.maven.project.MavenProject; import org.jetbrains.idea.maven.project.MavenProjectsManager; import org.jetbrains.idea.maven.utils.Path; -import org.jetbrains.idea.maven.utils.Url; import java.io.File; import java.util.ArrayList; @@ -45,31 +45,33 @@ public class MavenFoldersImporter { final MavenProjectsManager manager = MavenProjectsManager.getInstance(project); final MavenImportingSettings settings = manager.getImportingSettings(); - ApplicationManager.getApplication().runWriteAction(new Runnable() { - public void run() { - List rootModels = new ArrayList(); - for (Module each : ModuleManager.getInstance(project).getModules()) { - MavenProject mavenProject = manager.findProject(each); - if (mavenProject == null) continue; + AccessToken accessToken = WriteAction.start(); + try { + List rootModels = new ArrayList(); + for (Module each : ModuleManager.getInstance(project).getModules()) { + MavenProject mavenProject = manager.findProject(each); + if (mavenProject == null) continue; - MavenRootModelAdapter a = new MavenRootModelAdapter(mavenProject, each, new MavenDefaultModifiableModelsProvider(project)); - new MavenFoldersImporter(mavenProject, settings, a).config(updateTargetFoldersOnly); + MavenRootModelAdapter a = new MavenRootModelAdapter(mavenProject, each, new MavenDefaultModifiableModelsProvider(project)); + new MavenFoldersImporter(mavenProject, settings, a).config(updateTargetFoldersOnly); - ModifiableRootModel model = a.getRootModel(); - if (model.isChanged()) { - rootModels.add(model); - } - else { - model.dispose(); - } + ModifiableRootModel model = a.getRootModel(); + if (model.isChanged()) { + rootModels.add(model); } - - if (!rootModels.isEmpty()) { - ModifiableRootModel[] modelsArray = rootModels.toArray(new ModifiableRootModel[rootModels.size()]); - ProjectRootManager.getInstance(project).multiCommit(modelsArray); + else { + model.dispose(); } } - }); + + if (!rootModels.isEmpty()) { + ModifiableRootModel[] modelsArray = rootModels.toArray(new ModifiableRootModel[rootModels.size()]); + ProjectRootManager.getInstance(project).multiCommit(modelsArray); + } + } + finally { + accessToken.finish(); + } } public MavenFoldersImporter(MavenProject mavenProject, MavenImportingSettings settings, MavenRootModelAdapter model) { diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsProcessorArtifactsDownloadingTask.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsProcessorArtifactsDownloadingTask.java index 5bc207ee652b..ddf7b4630d9f 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsProcessorArtifactsDownloadingTask.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsProcessorArtifactsDownloadingTask.java @@ -15,7 +15,8 @@ */ package org.jetbrains.idea.maven.project; -import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.AccessToken; +import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ex.ProjectRootManagerEx; import com.intellij.openapi.util.AsyncResult; @@ -58,11 +59,13 @@ public class MavenProjectsProcessorArtifactsDownloadingTask implements MavenProj // todo: hack to update all file pointers. MavenUtil.invokeLater(project, new Runnable() { public void run() { - ApplicationManager.getApplication().runWriteAction(new Runnable() { - public void run() { - ProjectRootManagerEx.getInstanceEx(project).makeRootsChange(EmptyRunnable.getInstance(), false, true); - } - }); + AccessToken accessToken = WriteAction.start(); + try { + ProjectRootManagerEx.getInstanceEx(project).makeRootsChange(EmptyRunnable.getInstance(), false, true); + } + finally { + accessToken.finish(); + } } }); } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenEnvironmentRegistrar.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenEnvironmentRegistrar.java index b778be3751be..90daa24baf34 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenEnvironmentRegistrar.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenEnvironmentRegistrar.java @@ -17,8 +17,10 @@ package org.jetbrains.idea.maven.utils; import com.intellij.ide.highlighter.XmlFileType; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.PathMacros; +import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.components.ApplicationComponent; import com.intellij.openapi.fileTypes.FileTypeManager; import org.jetbrains.annotations.NotNull; @@ -42,12 +44,14 @@ public class MavenEnvironmentRegistrar implements ApplicationComponent { private void registerFileTypes() { // we should not change file types in unit test mode if (ApplicationManager.getApplication().isUnitTestMode()) return; - ApplicationManager.getApplication().runWriteAction(new Runnable() { - @Override - public void run() { - FileTypeManager.getInstance().associateExtension(XmlFileType.INSTANCE, MavenConstants.POM_EXTENSION); - } - }); + + AccessToken accessToken = WriteAction.start(); + try { + FileTypeManager.getInstance().associateExtension(XmlFileType.INSTANCE, MavenConstants.POM_EXTENSION); + } + finally { + accessToken.finish(); + } } private void registerPathVariable() { diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenRehighlighter.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenRehighlighter.java index 265b0b24beb4..e51a3ab0b80c 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenRehighlighter.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenRehighlighter.java @@ -16,6 +16,7 @@ package org.jetbrains.idea.maven.utils; import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.editor.Document; @@ -94,13 +95,14 @@ public class MavenRehighlighter extends MavenSimpleProjectComponent { } public static void rehighlight(final Project project, final MavenProject mavenProject) { - ApplicationManager.getApplication().runReadAction(new Runnable() { - @Override - public void run() { - if (project.isDisposed()) return; - ServiceManager.getService(project, MavenRehighlighter.class).myQueue.queue(new MyUpdate(project, mavenProject)); - } - }); + AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock(); + try { + if (project.isDisposed()) return; + ServiceManager.getService(project, MavenRehighlighter.class).myQueue.queue(new MyUpdate(project, mavenProject)); + } + finally { + accessToken.finish(); + } } private static class MyUpdate extends Update { diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/library/RepositoryAttachHandler.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/library/RepositoryAttachHandler.java index 3c2c5d14d320..83b1ffb1795a 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/library/RepositoryAttachHandler.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/library/RepositoryAttachHandler.java @@ -18,8 +18,10 @@ package org.jetbrains.idea.maven.utils.library; import com.intellij.notification.Notification; import com.intellij.notification.NotificationType; import com.intellij.notification.Notifications; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; +import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.progress.Task; @@ -85,17 +87,19 @@ public class RepositoryAttachHandler { public boolean process(final List artifacts) { final boolean nothingRetrieved = artifacts.isEmpty(); if (!nothingRetrieved) { - ApplicationManager.getApplication().runWriteAction(new Runnable() { - public void run() { - final List roots = createRoots(artifacts, copyTo); - result.set(new NewLibraryConfiguration(coord, RepositoryLibraryType.getInstance(), new RepositoryLibraryProperties(coord)) { - @Override - public void addRoots(@NotNull LibraryEditor editor) { - editor.addRoots(roots); - } - }); - } - }); + AccessToken accessToken = WriteAction.start(); + try { + final List roots = createRoots(artifacts, copyTo); + result.set(new NewLibraryConfiguration(coord, RepositoryLibraryType.getInstance(), new RepositoryLibraryProperties(coord)) { + @Override + public void addRoots(@NotNull LibraryEditor editor) { + editor.addRoots(roots); + } + }); + } + finally { + accessToken.finish(); + } } final StringBuilder sb = new StringBuilder(); final String title; diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/DependenciesImportingTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/DependenciesImportingTest.java index e2aeb5b866ac..d5ac1ec9cb63 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/DependenciesImportingTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/DependenciesImportingTest.java @@ -15,7 +15,9 @@ */ package org.jetbrains.idea.maven.importing; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.module.Module; import com.intellij.openapi.roots.*; import com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable; @@ -2047,11 +2049,13 @@ public class DependenciesImportingTest extends MavenImportingTestCase { } private Library createProjectLibrary(final String libraryName) { - return ApplicationManager.getApplication().runWriteAction(new Computable() { - public Library compute() { - return ProjectLibraryTable.getInstance(myProject).createLibrary(libraryName); - } - }); + AccessToken accessToken = WriteAction.start(); + try { + return ProjectLibraryTable.getInstance(myProject).createLibrary(libraryName); + } + finally { + accessToken.finish(); + } } private void createAndAddProjectLibrary(final String moduleName, final String libraryName) { From e2d6cb5685cfbebfb1e4442287ad48277621dd8d Mon Sep 17 00:00:00 2001 From: Sergey Evdokimov Date: Thu, 2 Feb 2012 19:31:56 +0400 Subject: [PATCH 29/43] Revert broken tests. --- .../2.5/maven-resources-plugin-2.5.jar | 0 .../2.5/maven-resources-plugin-2.5.jar.sha1 | 1 - .../2.5/maven-resources-plugin-2.5.pom | 203 ------------------ .../2.5/maven-resources-plugin-2.5.pom.sha1 | 1 - ...nExtensionCompletionAndResolutionTest.java | 3 +- ...avenPluginCompletionAndResolutionTest.java | 58 +---- 6 files changed, 2 insertions(+), 264 deletions(-) delete mode 100644 plugins/maven/src/test/data/plugins/org/apache/maven/plugins/maven-resources-plugin/2.5/maven-resources-plugin-2.5.jar delete mode 100644 plugins/maven/src/test/data/plugins/org/apache/maven/plugins/maven-resources-plugin/2.5/maven-resources-plugin-2.5.jar.sha1 delete mode 100644 plugins/maven/src/test/data/plugins/org/apache/maven/plugins/maven-resources-plugin/2.5/maven-resources-plugin-2.5.pom delete mode 100644 plugins/maven/src/test/data/plugins/org/apache/maven/plugins/maven-resources-plugin/2.5/maven-resources-plugin-2.5.pom.sha1 diff --git a/plugins/maven/src/test/data/plugins/org/apache/maven/plugins/maven-resources-plugin/2.5/maven-resources-plugin-2.5.jar b/plugins/maven/src/test/data/plugins/org/apache/maven/plugins/maven-resources-plugin/2.5/maven-resources-plugin-2.5.jar deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/plugins/maven/src/test/data/plugins/org/apache/maven/plugins/maven-resources-plugin/2.5/maven-resources-plugin-2.5.jar.sha1 b/plugins/maven/src/test/data/plugins/org/apache/maven/plugins/maven-resources-plugin/2.5/maven-resources-plugin-2.5.jar.sha1 deleted file mode 100644 index 66f7045df9cb..000000000000 --- a/plugins/maven/src/test/data/plugins/org/apache/maven/plugins/maven-resources-plugin/2.5/maven-resources-plugin-2.5.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -4d0907396ac6a770e05c81f6e8ed6348740f86a0 diff --git a/plugins/maven/src/test/data/plugins/org/apache/maven/plugins/maven-resources-plugin/2.5/maven-resources-plugin-2.5.pom b/plugins/maven/src/test/data/plugins/org/apache/maven/plugins/maven-resources-plugin/2.5/maven-resources-plugin-2.5.pom deleted file mode 100644 index f74aea0ce484..000000000000 --- a/plugins/maven/src/test/data/plugins/org/apache/maven/plugins/maven-resources-plugin/2.5/maven-resources-plugin-2.5.pom +++ /dev/null @@ -1,203 +0,0 @@ - - - - - - 4.0.0 - - - maven-plugins - org.apache.maven.plugins - 19 - ../maven-plugins/pom.xml - - - maven-resources-plugin - 2.5 - maven-plugin - - Maven Resources Plugin - - The Resources Plugin handles the copying of project resources to the output - directory. There are two different kinds of resources: main resources and test resources. The - difference is that the main resources are the resources associated to the main - source code while the test resources are associated to the test source code. - Thus, this allows the separation of resources for the main source code and its - unit tests. - - 2001 - - - ${mavenVersion} - - - - scm:svn:http://svn.apache.org/repos/asf/maven/plugins/tags/maven-resources-plugin-2.5 - scm:svn:https://svn.apache.org/repos/asf/maven/plugins/tags/maven-resources-plugin-2.5 - http://svn.apache.org/viewvc/maven/plugins/tags/maven-resources-plugin-2.5 - - - JIRA - http://jira.codehaus.org/browse/MRESOURCES - - - - 1.0 - 2.0.6 - - - - - org.apache.maven - maven-plugin-api - ${mavenVersion} - - - org.apache.maven - maven-project - ${mavenVersion} - - - org.apache.maven - maven-core - ${mavenVersion} - - - org.apache.maven - maven-artifact - ${mavenVersion} - - - org.apache.maven - maven-settings - ${mavenVersion} - - - org.apache.maven - maven-model - ${mavenVersion} - - - org.apache.maven - maven-monitor - ${mavenVersion} - - - - org.codehaus.plexus - plexus-container-default - 1.0-alpha-9-stable-1 - - - - org.codehaus.plexus - plexus-utils - 2.0.5 - - - - org.apache.maven.shared - maven-filtering - ${mavenFilteringVersion} - - - - org.codehaus.plexus - plexus-interpolation - 1.13 - - - - org.apache.maven.shared - maven-plugin-testing-harness - 1.0-beta-1 - test - - - commons-io - commons-io - 1.4 - test - - - - - - run-its - - - - org.apache.maven.plugins - maven-jar-plugin - - - - test-jar - - - - - - org.codehaus.plexus - plexus-maven-plugin - - - - test-descriptor - - - - - - org.apache.maven.plugins - maven-invoker-plugin - - true - src/it - - **/pom.xml - - verify - ${project.build.directory}/local-repo - - clean - process-test-resources - - src/it/settings.xml - ${project.build.directory}/it - - fromExecProps - - - - - integration-test - - install - run - - - - - - - - - diff --git a/plugins/maven/src/test/data/plugins/org/apache/maven/plugins/maven-resources-plugin/2.5/maven-resources-plugin-2.5.pom.sha1 b/plugins/maven/src/test/data/plugins/org/apache/maven/plugins/maven-resources-plugin/2.5/maven-resources-plugin-2.5.pom.sha1 deleted file mode 100644 index ed141e784c90..000000000000 --- a/plugins/maven/src/test/data/plugins/org/apache/maven/plugins/maven-resources-plugin/2.5/maven-resources-plugin-2.5.pom.sha1 +++ /dev/null @@ -1 +0,0 @@ -2d44c4a29ea56775c87002edb5aa23aab47e71ac diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenExtensionCompletionAndResolutionTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenExtensionCompletionAndResolutionTest.java index c0d3a9cee077..abb177cb9160 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenExtensionCompletionAndResolutionTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenExtensionCompletionAndResolutionTest.java @@ -65,7 +65,7 @@ public class MavenExtensionCompletionAndResolutionTest extends MavenDomWithIndic " " + ""); - assertCompletionVariants(myProjectPom, "maven-compiler-plugin", "maven-war-plugin", "maven-eclipse-plugin", "maven-surefire-plugin", "maven-resources-plugin"); + assertCompletionVariants(myProjectPom, "maven-compiler-plugin", "maven-war-plugin", "maven-eclipse-plugin", "maven-surefire-plugin"); } public void testArtifactWithoutGroupCompletion() throws Exception { @@ -86,7 +86,6 @@ public class MavenExtensionCompletionAndResolutionTest extends MavenDomWithIndic "maven-war-plugin", "maven-surefire-plugin", "build-helper-maven-plugin", - "maven-resources-plugin", "maven-eclipse-plugin"); } diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenPluginCompletionAndResolutionTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenPluginCompletionAndResolutionTest.java index b98768519a1e..eaea5c74b3c3 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenPluginCompletionAndResolutionTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenPluginCompletionAndResolutionTest.java @@ -71,7 +71,7 @@ public class MavenPluginCompletionAndResolutionTest extends MavenDomWithIndicesT " " + ""); - assertCompletionVariants(myProjectPom, "maven-compiler-plugin", "maven-war-plugin", "maven-surefire-plugin", "maven-eclipse-plugin", "maven-resources-plugin"); + assertCompletionVariants(myProjectPom, "maven-compiler-plugin", "maven-war-plugin", "maven-surefire-plugin", "maven-eclipse-plugin"); } public void testArtifactWithoutGroupCompletion() throws Exception { @@ -92,7 +92,6 @@ public class MavenPluginCompletionAndResolutionTest extends MavenDomWithIndicesT "maven-war-plugin", "build-helper-maven-plugin", "maven-surefire-plugin", - "maven-resources-plugin", "maven-eclipse-plugin"); } @@ -903,59 +902,4 @@ public class MavenPluginCompletionAndResolutionTest extends MavenDomWithIndicesT assertCompletionVariants(myProjectPom); } - - public void testRequiringParameter() throws Throwable { - createProjectPom("test" + - "project" + - "1" + - - "" + - " " + - " \n" + - " maven-resources-plugin\n" + - " \n" + - " <outputDirectory/>\n" + - " \n" + - " \n" + - - " \n" + - " maven-resources-plugin\n" + - "" + - " \n" + - " aaa\n" + - " \n" + - " \n" + - - " \n" + - " maven-resources-plugin\n" + - "" + - " \n" + - " \n" + - " \n" + - - " \n" + - " maven-resources-plugin\n" + - " " + - " " + - " " + - " copy-resources" + - " resources" + - " " + - " <configuration>\n" + - " \n" + - " " + - " " + - " " + - "" + - " \n" + - " \n" + - " \n" + - - - " " + - ""); - - checkHighlighting(); - } - } From d0e514c44ffc86e5c2eac450e51072694d241880 Mon Sep 17 00:00:00 2001 From: Dmitry Boulytchev Date: Thu, 2 Feb 2012 19:46:18 +0400 Subject: [PATCH 30/43] Finishing setting up tests (compiler server). --- .../jetbrains/ether/IncrementalTestCase.java | 21 +++++++- .../jetbrains/ether/VolatileFileAppender.java | 52 +++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 jps/jps-builders/testSrc/org/jetbrains/ether/VolatileFileAppender.java diff --git a/jps/jps-builders/testSrc/org/jetbrains/ether/IncrementalTestCase.java b/jps/jps-builders/testSrc/org/jetbrains/ether/IncrementalTestCase.java index a28814e37b73..5c69838f60f1 100644 --- a/jps/jps-builders/testSrc/org/jetbrains/ether/IncrementalTestCase.java +++ b/jps/jps-builders/testSrc/org/jetbrains/ether/IncrementalTestCase.java @@ -21,6 +21,7 @@ import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; import junit.framework.TestCase; import junitx.framework.FileAssert; +import org.apache.log4j.FileAppender; import org.apache.log4j.Level; import org.apache.log4j.PropertyConfigurator; import org.jetbrains.annotations.NonNls; @@ -64,6 +65,23 @@ public abstract class IncrementalTestCase extends TestCase { } } + static VolatileFileAppender myAppender = null; + + static void setAppender (final VolatileFileAppender app) { + myAppender = app; + } + + static void closeAppender () { + if (myAppender != null) { + try { + myAppender.closeStream(); + } + catch (IOException e) { + throw new RuntimeException(e); + } + } + } + static { Logger.setFactory(new Logger.Factory() { @Override @@ -156,6 +174,7 @@ public abstract class IncrementalTestCase extends TestCase { super.tearDown(); } finally { + closeAppender(); delete(new File(workDir)); } } @@ -268,7 +287,7 @@ public abstract class IncrementalTestCase extends TestCase { final Properties properties = new Properties(); properties.setProperty("log4j.rootCategory", "INFO, A1"); - properties.setProperty("log4j.appender.A1", "org.apache.log4j.FileAppender"); + properties.setProperty("log4j.appender.A1", "org.jetbrains.ether.VolatileFileAppender"); properties.setProperty("log4j.appender.A1.file", getWorkDir() + ".log"); properties.setProperty("log4j.appender.A1.layout", "org.apache.log4j.PatternLayout"); properties.setProperty("log4j.appender.A1.layout.ConversionPattern", "%m%n"); diff --git a/jps/jps-builders/testSrc/org/jetbrains/ether/VolatileFileAppender.java b/jps/jps-builders/testSrc/org/jetbrains/ether/VolatileFileAppender.java new file mode 100644 index 000000000000..9c1947bb8d07 --- /dev/null +++ b/jps/jps-builders/testSrc/org/jetbrains/ether/VolatileFileAppender.java @@ -0,0 +1,52 @@ +/* + * Copyright 2000-2012 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 org.jetbrains.ether; + +import org.apache.log4j.FileAppender; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; + +/** + * Created with IntelliJ IDEA. + * User: db + * Date: 02.02.12 + * Time: 18:27 + * To change this template use File | Settings | File Templates. + */ + +public class VolatileFileAppender extends FileAppender { + private OutputStream myStream = null; + + public VolatileFileAppender() { + super(); + IncrementalTestCase.setAppender(this); + } + + void closeStream () throws IOException { + if (myStream != null){ + myStream.close(); + myStream = null; + } + } + + @Override + protected OutputStreamWriter createWriter(final OutputStream os) { + myStream = os; + return super.createWriter(os); + } +} From 861bb94831b103069beacb7fae8a0634d57c43a7 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Thu, 2 Feb 2012 16:57:16 +0100 Subject: [PATCH 31/43] +multiple selection and operations performing --- .../openapi/diff/impl/dir/DirDiffElement.java | 10 ++-- .../diff/impl/dir/DirDiffOperation.java | 2 + .../openapi/diff/impl/dir/DirDiffPanel.form | 41 +++++++++------- .../openapi/diff/impl/dir/DirDiffPanel.java | 47 ++++++++++++------- .../diff/impl/dir/DirDiffTableModel.java | 1 + 5 files changed, 61 insertions(+), 40 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffElement.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffElement.java index 4c5cc4cd90e0..77673fecef21 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffElement.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffElement.java @@ -49,20 +49,20 @@ public class DirDiffElement { myTargetLength = target == null || target.isContainer() ? -1 : target.getSize(); myName = name; if (type == DType.ERROR) { - myDefaultOperation = DirDiffOperation.NONE; + myDefaultOperation = NONE; } else if (isSource()) { myDefaultOperation = COPY_TO; } else if (isTarget()) { - myDefaultOperation = DirDiffOperation.COPY_FROM; + myDefaultOperation = COPY_FROM; } else if (type == DType.EQUAL) { - myDefaultOperation = DirDiffOperation.EQUAL; + myDefaultOperation = EQUAL; } else if (type == DType.CHANGED) { assert source != null; - myDefaultOperation = DirDiffOperation.MERGE; + myDefaultOperation = MERGE; } } @@ -180,7 +180,7 @@ public class DirDiffElement { } else if (myType == DType.TARGET) { myOperation = op == COPY_FROM ? DELETE : op == DELETE ? NONE : COPY_FROM; } else if (myType == DType.CHANGED) { - myOperation = op == MERGE ? COPY_FROM : op == COPY_FROM ? COPY_TO : op == COPY_TO ? NONE : MERGE; + myOperation = op == MERGE ? COPY_FROM : op == COPY_FROM ? COPY_TO : MERGE; } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffOperation.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffOperation.java index b9a7b9565e00..d9a543f4d952 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffOperation.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffOperation.java @@ -47,6 +47,8 @@ public enum DirDiffOperation { return FileStatus.COLOR_ADDED; case MERGE: return FileStatus.COLOR_MODIFIED; + case DELETE: + return FileStatus.DELETED.getColor(); case EQUAL: case NONE: } diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.form b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.form index e4f768b3e5da..058754e895dd 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.form +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.form @@ -36,23 +36,6 @@ - - - - - - - - - - - - - - - - - @@ -144,6 +127,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.java index 8b9f6e4965f4..ec9c59ce7633 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.java @@ -68,6 +68,7 @@ public class DirDiffPanel implements Disposable { private JPanel myRootPanel; private JPanel myFilterPanel; private JBLabel myFilterLabel; + private JPanel myFilesPanel; private FilterComponent myFilter; private final DirDiffTableModel myModel; public JLabel myErrorLabel; @@ -95,7 +96,7 @@ public class DirDiffPanel implements Disposable { final DirDiffTableCellRenderer renderer = new DirDiffTableCellRenderer(myTable); myTable.setDefaultRenderer(Object.class, renderer); - myTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + myTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); final Project project = myModel.getProject(); myTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override @@ -106,10 +107,12 @@ public class DirDiffPanel implements Disposable { final DirDiffElement first = myModel.getElementAt(firstIndex); if (last == null || first == null) return; if (last.isSeparator()) { - myTable.getSelectionModel().setLeadSelectionIndex(lastIndex + ((lastIndex < firstIndex) ? 1 : -1)); + final int ind = lastIndex + ((lastIndex < firstIndex) ? 1 : -1); + myTable.getSelectionModel().addSelectionInterval(ind, ind); } else if (first.isSeparator()) { - myTable.getSelectionModel().setLeadSelectionIndex(firstIndex + ((firstIndex < lastIndex) ? 1 : -1)); + final int ind = firstIndex + ((firstIndex < lastIndex) ? 1 : -1); + myTable.getSelectionModel().addSelectionInterval(ind, ind); } else { update(false); @@ -121,7 +124,7 @@ public class DirDiffPanel implements Disposable { new AnAction("Change diff operation") { @Override public void actionPerformed(AnActionEvent e) { - changeOperationForSelectedRow(); + changeOperationForSelection(); } }.registerCustomShortcutSet(CustomShortcutSet.fromString("SPACE"), myTable); myTable.addMouseListener(new MouseAdapter() { @@ -132,7 +135,7 @@ public class DirDiffPanel implements Disposable { final int col = myTable.columnAtPoint(e.getPoint()); if (row != -1 && col == ((myTable.getColumnCount() - 1) / 2)) { - changeOperationForSelectedRow(); + changeOperationForSelection(); } } } @@ -142,9 +145,11 @@ public class DirDiffPanel implements Disposable { @Override public void keyPressed(KeyEvent e) { final int keyCode = e.getKeyCode(); - final int rows = myTable.getRowCount(); - int row = myTable.getSelectedRow(); - if (keyCode == KeyEvent.VK_DOWN && row != rows - 1) { + final int rowCount = myTable.getRowCount(); + int row = myTable.getSelectionModel().getLeadSelectionIndex(); + final int[] rows = myTable.getSelectedRows(); + if (rows.length == 0) return; + if (keyCode == KeyEvent.VK_DOWN && row < rowCount - 1) { row++; final DirDiffElement element = myModel.getElementAt(row); if (element == null) return; @@ -152,7 +157,7 @@ public class DirDiffPanel implements Disposable { row++; } } - else if (keyCode == KeyEvent.VK_UP && row != 0) { + else if (keyCode == KeyEvent.VK_UP && row > 0) { row--; final DirDiffElement element = myModel.getElementAt(row); if (element == null) return; @@ -167,7 +172,7 @@ public class DirDiffPanel implements Disposable { if (element == null) return; if (!element.isSeparator()) { e.consume(); - myTable.changeSelection(row, (myModel.getColumnCount() - 1) / 2, false, false); + myTable.changeSelection(row, (myModel.getColumnCount() - 1) / 2, false, e.isShiftDown()); } } }); @@ -190,9 +195,14 @@ public class DirDiffPanel implements Disposable { final ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar("DirDiff", actions, true); registerCustomShortcuts(actions, myTable); myToolBarPanel.add(toolbar.getComponent(), BorderLayout.CENTER); + final JBLabel label = new JBLabel("Use Space button or mouse click to change operation for the selected elements. Enter to perform.", SwingConstants.CENTER); + label.setForeground(UIUtil.getInactiveTextColor()); + UIUtil.applyStyle(UIUtil.ComponentStyle.MINI, label); + myFilesPanel.add(label, BorderLayout.SOUTH); final JBLoadingPanel loadingPanel = new JBLoadingPanel(new BorderLayout(), wnd.getDisposable()); loadingPanel.addListener(new JBLoadingPanelListener.Adapter() { boolean showHelp = true; + @Override public void onLoadingFinish() { if (showHelp && myModel.isOperationsEnabled() && myModel.getRowCount() > 0) { @@ -200,7 +210,7 @@ public class DirDiffPanel implements Disposable { if (count < 3) { JBPopupFactory.getInstance().createBalloonBuilder(new JLabel(" Use Space button to change operation")) .setFadeoutTime(5000) - .setContentInsets(new Insets(15,15,15,15)) + .setContentInsets(new Insets(15, 15, 15, 15)) .createBalloon().show(new RelativePoint(myTable, new Point(myTable.getWidth() / 2, 0)), Balloon.Position.above); PropertiesComponent.getInstance().setValue("dir.diff.space.button.info", String.valueOf(count + 1)); } @@ -308,13 +318,14 @@ public class DirDiffPanel implements Disposable { } } - private void changeOperationForSelectedRow() { - final int row = myTable.getSelectedRow(); - if (row != -1) { - final DirDiffElement element = myModel.getElementAt(row); - if (element != null) { - element.setNextOperation(); - myModel.fireTableRowsUpdated(row, row); + private void changeOperationForSelection() { + for (int row : myTable.getSelectedRows()) { + if (row != -1) { + final DirDiffElement element = myModel.getElementAt(row); + if (element != null) { + element.setNextOperation(); + myModel.fireTableRowsUpdated(row, row); + } } } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java index b3af691dcba4..7dcc9af542d5 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java @@ -109,6 +109,7 @@ public class DirDiffTableModel extends AbstractTableModel implements DirDiffMode case EQUAL: if (!mySettings.showEqual) i.remove(); break; + case ERROR: } } From 9d0b4a01e82d526c80d6ba20a0905483e2d4927c Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Thu, 2 Feb 2012 17:02:03 +0100 Subject: [PATCH 32/43] add server-based make test root --- jps/jps-builders/jps-builders.iml | 1 + .../testSrc/org/jetbrains/ether/IncrementalTestCase.java | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/jps/jps-builders/jps-builders.iml b/jps/jps-builders/jps-builders.iml index a7c2adfe8125..67753b980806 100644 --- a/jps/jps-builders/jps-builders.iml +++ b/jps/jps-builders/jps-builders.iml @@ -4,6 +4,7 @@ + diff --git a/jps/jps-builders/testSrc/org/jetbrains/ether/IncrementalTestCase.java b/jps/jps-builders/testSrc/org/jetbrains/ether/IncrementalTestCase.java index 5c69838f60f1..bfffa1a8767d 100644 --- a/jps/jps-builders/testSrc/org/jetbrains/ether/IncrementalTestCase.java +++ b/jps/jps-builders/testSrc/org/jetbrains/ether/IncrementalTestCase.java @@ -21,7 +21,6 @@ import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; import junit.framework.TestCase; import junitx.framework.FileAssert; -import org.apache.log4j.FileAppender; import org.apache.log4j.Level; import org.apache.log4j.PropertyConfigurator; import org.jetbrains.annotations.NonNls; From 1db5e23f95afada809ae411ed41f19df54647e9e Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Thu, 2 Feb 2012 20:19:21 +0400 Subject: [PATCH 33/43] Show merge commit content correctly on "Show All Affected Paths" invoked from File History --- .../src/git4idea/actions/GitShowAllSubmittedFilesAction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/git4idea/src/git4idea/actions/GitShowAllSubmittedFilesAction.java b/plugins/git4idea/src/git4idea/actions/GitShowAllSubmittedFilesAction.java index ceb6ddaee938..a97f569e70b8 100644 --- a/plugins/git4idea/src/git4idea/actions/GitShowAllSubmittedFilesAction.java +++ b/plugins/git4idea/src/git4idea/actions/GitShowAllSubmittedFilesAction.java @@ -102,7 +102,7 @@ public class GitShowAllSubmittedFilesAction extends AnAction implements DumbAwar indicator.setIndeterminate(true); try { VirtualFile vcsRoot = GitUtil.getGitRoot(file); - final CommittedChangeList changeList = GitChangeUtils.getRevisionChanges(project, vcsRoot, revision, false); + final CommittedChangeList changeList = GitChangeUtils.getRevisionChanges(project, vcsRoot, revision, true); if (changeList != null) { UIUtil.invokeLaterIfNeeded(new Runnable() { public void run() { From 8fac3f69744254049857556cf6963122d6da3fc1 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Thu, 2 Feb 2012 17:27:19 +0100 Subject: [PATCH 34/43] NPE in Swing FontMetrics --- .../com/intellij/uiDesigner/core/Util.java | 44 ++++++++++++------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/platform/forms_rt/src/com/intellij/uiDesigner/core/Util.java b/platform/forms_rt/src/com/intellij/uiDesigner/core/Util.java index edeb753c7788..819bc1564a6d 100644 --- a/platform/forms_rt/src/com/intellij/uiDesigner/core/Util.java +++ b/platform/forms_rt/src/com/intellij/uiDesigner/core/Util.java @@ -23,30 +23,44 @@ public final class Util { public static final int DEFAULT_INDENT = 10; public static Dimension getMinimumSize(final Component component, final GridConstraints constraints, final boolean addIndent){ - final Dimension size = getSize(constraints.myMinimumSize, component.getMinimumSize()); - if (addIndent) { - size.width += DEFAULT_INDENT * constraints.getIndent(); + try { + final Dimension size = getSize(constraints.myMinimumSize, component.getMinimumSize()); + if (addIndent) { + size.width += DEFAULT_INDENT * constraints.getIndent(); + } + return size; + } catch (NullPointerException npe) { //IDEA-80722 + return new Dimension(0,0); } - return size; } public static Dimension getMaximumSize(final Component component, final GridConstraints constraints, final boolean addIndent){ - //[anton] we use only our property for maximum size. - // JButton reports that its max size = pref size, so it is impossible to make a column of same sized buttons. - // Probably there are other bad cases... - final Dimension size = getSize(constraints.myMaximumSize, MAX_SIZE); - if (addIndent && size.width < MAX_SIZE.width) { - size.width += DEFAULT_INDENT * constraints.getIndent(); + try { + //[anton] we use only our property for maximum size. + // JButton reports that its max size = pref size, so it is impossible to make a column of same sized buttons. + // Probably there are other bad cases... + final Dimension size = getSize(constraints.myMaximumSize, MAX_SIZE); + if (addIndent && size.width < MAX_SIZE.width) { + size.width += DEFAULT_INDENT * constraints.getIndent(); + } + return size; + } + catch (NullPointerException e) {//IDEA-80722 + return new Dimension(0,0); } - return size; } public static Dimension getPreferredSize(final Component component, final GridConstraints constraints, final boolean addIndent) { - final Dimension size = getSize(constraints.myPreferredSize, component.getPreferredSize()); - if (addIndent) { - size.width += DEFAULT_INDENT * constraints.getIndent(); + try { + final Dimension size = getSize(constraints.myPreferredSize, component.getPreferredSize()); + if (addIndent) { + size.width += DEFAULT_INDENT * constraints.getIndent(); + } + return size; + } + catch (NullPointerException e) {//IDEA-80722 + return new Dimension(0,0); } - return size; } private static Dimension getSize(final Dimension overridenSize, final Dimension ownSize){ From 5e12046368f70f012e6631dd0c1b2eae6d692638 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Thu, 2 Feb 2012 16:56:54 +0400 Subject: [PATCH 35/43] Cleanup --- .../intellij/ide/actions/OpenProjectAction.java | 16 ++++++++-------- .../OpenProjectFileChooserDescriptor.java | 6 +++--- .../vfs/newvfs/impl/VirtualFileSystemEntry.java | 8 ++++---- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/java/idea-ui/src/com/intellij/ide/actions/OpenProjectAction.java b/java/idea-ui/src/com/intellij/ide/actions/OpenProjectAction.java index 11db267cb111..2b0e91667096 100644 --- a/java/idea-ui/src/com/intellij/ide/actions/OpenProjectAction.java +++ b/java/idea-ui/src/com/intellij/ide/actions/OpenProjectAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -24,7 +24,7 @@ import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.fileChooser.FileChooser; import com.intellij.openapi.fileChooser.FileChooserDescriptor; -import com.intellij.openapi.fileChooser.ex.FileChooserDialogImpl; +import com.intellij.openapi.fileChooser.FileChooserDialog; import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.SystemInfo; @@ -59,21 +59,21 @@ public class OpenProjectAction extends AnAction implements DumbAware { descriptor.setDescription(IdeBundle.message("filter.project.files", StringUtil.join(extensions, ", "))); VirtualFile userHomeDir = null; - if (SystemInfo.isMac || SystemInfo.isLinux) { + if (SystemInfo.isUnix) { final String home = SystemProperties.getUserHome(); if (home != null) { userHomeDir = LocalFileSystem.getInstance().findFileByIoFile(new File(home)); } } - descriptor.putUserData(FileChooserDialogImpl.PREFER_LAST_OVER_TO_SELECT, Boolean.TRUE); + descriptor.putUserData(FileChooserDialog.PREFER_LAST_OVER_TO_SELECT, Boolean.TRUE); - FileChooser.chooseFilesWithSlideEffect(descriptor, project, userHomeDir,new Consumer() { + FileChooser.chooseFilesWithSlideEffect(descriptor, project, userHomeDir, new Consumer() { @Override public void consume(final VirtualFile[] files) { - if (files.length == 0 || files[0] == null) return; - - ProjectUtil.openOrImport(files[0].getPath(), project, false); + if (files.length == 1 && files[0] != null) { + ProjectUtil.openOrImport(files[0].getPath(), project, false); + } } }); } diff --git a/platform/platform-impl/src/com/intellij/ide/actions/OpenProjectFileChooserDescriptor.java b/platform/platform-impl/src/com/intellij/ide/actions/OpenProjectFileChooserDescriptor.java index 6bdf1a64de7e..4ce249483e4a 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/OpenProjectFileChooserDescriptor.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/OpenProjectFileChooserDescriptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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,7 +16,7 @@ package com.intellij.ide.actions; import com.intellij.ide.highlighter.ProjectFileType; -import com.intellij.openapi.application.impl.ApplicationInfoImpl; +import com.intellij.openapi.application.ex.ApplicationInfoEx; import com.intellij.openapi.fileChooser.FileChooserDescriptor; import com.intellij.openapi.fileChooser.FileElement; import com.intellij.openapi.project.Project; @@ -28,7 +28,7 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; public class OpenProjectFileChooserDescriptor extends FileChooserDescriptor { - private static final Icon ourProjectIcon = IconLoader.getIcon(ApplicationInfoImpl.getInstanceEx().getSmallIconUrl()); + private static final Icon ourProjectIcon = IconLoader.getIcon(ApplicationInfoEx.getInstanceEx().getSmallIconUrl()); public OpenProjectFileChooserDescriptor(final boolean chooseFiles) { super(chooseFiles, true, chooseFiles, chooseFiles, false, false); diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualFileSystemEntry.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualFileSystemEntry.java index 7dca2a0f3ba4..08cf80c6f47e 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualFileSystemEntry.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualFileSystemEntry.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -204,7 +204,7 @@ public abstract class VirtualFileSystemEntry extends NewVirtualFile { return myParent == null ? length : myParent.getPathLength() + length + 1; } - int appendPathOnFileSystem(@NotNull char[] chars, int pos) { + protected int appendPathOnFileSystem(@NotNull char[] chars, int pos) { if (myParent != null) { pos = myParent.appendPathOnFileSystem(chars, pos); } @@ -225,8 +225,8 @@ public abstract class VirtualFileSystemEntry extends NewVirtualFile { return copyString(chars, pos, suffix); } byte[] bytes = (byte[]) o; - int len = bytes.length; - for (int i = 0; i < len; i++) { + //noinspection ForLoopReplaceableByForEach + for (int i = 0, len = bytes.length; i < len; i++) { chars[pos++] = (char)bytes[i]; } return copyString(chars, pos, suffix); From 5d3712fd3e4cb24719daf4450d6f54b5562b0581 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Thu, 2 Feb 2012 20:37:18 +0400 Subject: [PATCH 36/43] Symlink icons in a file chooser --- .../src/com/intellij/util/IconUtil.java | 59 +++++++++---------- .../fileChooser/FileChooserDescriptor.java | 29 +++++---- .../OpenProjectFileChooserDescriptor.java | 32 +++++----- .../importWizard/EclipseImportBuilder.java | 14 ++--- 4 files changed, 71 insertions(+), 63 deletions(-) diff --git a/platform/core-api/src/com/intellij/util/IconUtil.java b/platform/core-api/src/com/intellij/util/IconUtil.java index 58b39d3287b6..3be59e668176 100644 --- a/platform/core-api/src/com/intellij/util/IconUtil.java +++ b/platform/core-api/src/com/intellij/util/IconUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -89,44 +89,43 @@ public class IconUtil { return new ImageIcon(img); } - public static Icon getIcon(final VirtualFile file, @Iconable.IconFlags final int flags, final Project project) { + public static Icon getIcon(final VirtualFile file, @Iconable.IconFlags final int flags, @Nullable final Project project) { Icon lastIcon = Iconable.LastComputedIcon.get(file, flags); final Icon base = lastIcon != null ? lastIcon : VirtualFilePresentation.getIcon(file); - return IconDeferrer.getInstance() - .defer(base, new FileIconKey(file, project, flags), new Function() { - @Override - public Icon fun(final FileIconKey key) { - VirtualFile file = key.getFile(); - int flags = key.getFlags(); - Project project = key.getProject(); + return IconDeferrer.getInstance().defer(base, new FileIconKey(file, project, flags), new NullableFunction() { + @Override + public Icon fun(final FileIconKey key) { + final VirtualFile file = key.getFile(); + final int flags = key.getFlags(); + final Project project = key.getProject(); - if (!file.isValid() || project != null && (project.isDisposed() || !wasEverInitialized(project))) return null; + if (!file.isValid() || project != null && (project.isDisposed() || !wasEverInitialized(project))) return null; - Icon providersIcon = getProvidersIcon(file, flags, project); - Icon icon = providersIcon == null ? VirtualFilePresentation.getIcon(file) : providersIcon; + final Icon providersIcon = getProvidersIcon(file, flags, project); + Icon icon = providersIcon == null ? VirtualFilePresentation.getIcon(file) : providersIcon; - final boolean dumb = project != null && DumbService.getInstance(project).isDumb(); - for (FileIconPatcher patcher : getPatchers()) { - if (dumb && !DumbService.isDumbAware(patcher)) { - continue; - } - - icon = patcher.patchIcon(icon, file, flags, project); + final boolean dumb = project != null && DumbService.getInstance(project).isDumb(); + for (FileIconPatcher patcher : getPatchers()) { + if (dumb && !DumbService.isDumbAware(patcher)) { + continue; } - if ((flags & Iconable.ICON_FLAG_READ_STATUS) != 0 && !file.isWritable()) { - icon = new LayeredIcon(icon, PlatformIcons.LOCKED_ICON); - } - if (file.isSymLink()) { - icon = new LayeredIcon(icon, PlatformIcons.SYMLINK_ICON); - } - - Iconable.LastComputedIcon.put(file, icon, flags); - - return icon; + icon = patcher.patchIcon(icon, file, flags, project); } - }); + + if ((flags & Iconable.ICON_FLAG_READ_STATUS) != 0 && !file.isWritable()) { + icon = new LayeredIcon(icon, PlatformIcons.LOCKED_ICON); + } + if (file.isSymLink()) { + icon = new LayeredIcon(icon, PlatformIcons.SYMLINK_ICON); + } + + Iconable.LastComputedIcon.put(file, icon, flags); + + return icon; + } + }); } @Nullable diff --git a/platform/platform-api/src/com/intellij/openapi/fileChooser/FileChooserDescriptor.java b/platform/platform-api/src/com/intellij/openapi/fileChooser/FileChooserDescriptor.java index 180e0f5a93d2..a9d648f433bb 100644 --- a/platform/platform-api/src/com/intellij/openapi/fileChooser/FileChooserDescriptor.java +++ b/platform/platform-api/src/com/intellij/openapi/fileChooser/FileChooserDescriptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -21,6 +21,7 @@ import com.intellij.openapi.fileTypes.FileTypes; import com.intellij.openapi.util.Iconable; import com.intellij.openapi.vfs.JarFileSystem; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.ui.LayeredIcon; import com.intellij.ui.UIBundle; import com.intellij.util.IconUtil; import com.intellij.util.PlatformIcons; @@ -169,27 +170,31 @@ public class FileChooserDescriptor implements Cloneable{ return true; } - public Icon getOpenIcon(VirtualFile virtualFile) { - if (virtualFile.isDirectory()) { - return PlatformIcons.DIRECTORY_OPEN_ICON; + public Icon getOpenIcon(final VirtualFile file) { + if (file.isDirectory()) { + return dressIcon(file, PlatformIcons.DIRECTORY_OPEN_ICON); } // deliberately pass project null: isJavaSourceFile() and excluded from compile information is unavailable for template project - return IconUtil.getIcon(virtualFile, Iconable.ICON_FLAG_READ_STATUS, null); + return IconUtil.getIcon(file, Iconable.ICON_FLAG_READ_STATUS, null); } - public Icon getClosedIcon(VirtualFile virtualFile) { - if (virtualFile.isDirectory()) { - return PlatformIcons.DIRECTORY_CLOSED_ICON; + + public Icon getClosedIcon(final VirtualFile file) { + if (file.isDirectory()) { + return dressIcon(file, PlatformIcons.DIRECTORY_CLOSED_ICON); } - return IconUtil.getIcon(virtualFile, Iconable.ICON_FLAG_READ_STATUS, null); + return IconUtil.getIcon(file, Iconable.ICON_FLAG_READ_STATUS, null); } - public String getName(VirtualFile virtualFile) { - return virtualFile.getPath(); + protected static Icon dressIcon(final VirtualFile file, final Icon baseIcon) { + return file.isSymLink() ? new LayeredIcon(baseIcon, PlatformIcons.SYMLINK_ICON) : baseIcon; } + public String getName(final VirtualFile file) { + return file.getPath(); + } @Nullable - public String getComment(VirtualFile virtualFile) { + public String getComment(final VirtualFile file) { return null; } diff --git a/platform/platform-impl/src/com/intellij/ide/actions/OpenProjectFileChooserDescriptor.java b/platform/platform-impl/src/com/intellij/ide/actions/OpenProjectFileChooserDescriptor.java index 4ce249483e4a..9ad62ed082c3 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/OpenProjectFileChooserDescriptor.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/OpenProjectFileChooserDescriptor.java @@ -38,28 +38,32 @@ public class OpenProjectFileChooserDescriptor extends FileChooserDescriptor { return isProjectDirectory(file) || isProjectFile(file); } - public Icon getOpenIcon(final VirtualFile virtualFile) { - if (isProjectDirectory(virtualFile)) return ourProjectIcon; - final Icon icon = getImporterIcon(virtualFile, true); - if(icon!=null){ - return icon; + public Icon getOpenIcon(final VirtualFile file) { + if (isProjectDirectory(file)) { + return dressIcon(file, ourProjectIcon); } - return super.getOpenIcon(virtualFile); + final Icon icon = getImporterIcon(file); + if (icon != null) { + return dressIcon(file, icon); + } + return super.getOpenIcon(file); } - public Icon getClosedIcon(final VirtualFile virtualFile) { - if (isProjectDirectory(virtualFile)) return ourProjectIcon; - final Icon icon = getImporterIcon(virtualFile, false); - if(icon!=null){ - return icon; + public Icon getClosedIcon(final VirtualFile file) { + if (isProjectDirectory(file)) { + return dressIcon(file, ourProjectIcon); } - return super.getClosedIcon(virtualFile); + final Icon icon = getImporterIcon(file); + if (icon != null) { + return dressIcon(file, icon); + } + return super.getClosedIcon(file); } @Nullable - public static Icon getImporterIcon(final VirtualFile virtualFile, final boolean open) { + private static Icon getImporterIcon(final VirtualFile virtualFile) { final ProjectOpenProcessor provider = ProjectOpenProcessor.getImportProvider(virtualFile); - if(provider!=null) { + if (provider != null) { return virtualFile.isDirectory() && provider.lookForProjectsInDirectory() ? ourProjectIcon : provider.getIcon(virtualFile); } return null; diff --git a/plugins/eclipse/src/org/jetbrains/idea/eclipse/importWizard/EclipseImportBuilder.java b/plugins/eclipse/src/org/jetbrains/idea/eclipse/importWizard/EclipseImportBuilder.java index b5e1beb045d6..d9ad18c22a24 100644 --- a/plugins/eclipse/src/org/jetbrains/idea/eclipse/importWizard/EclipseImportBuilder.java +++ b/plugins/eclipse/src/org/jetbrains/idea/eclipse/importWizard/EclipseImportBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -373,16 +373,16 @@ public class EclipseImportBuilder extends ProjectImportBuilder implement private static void createEclipseLibrary(final Project project, final Collection libraries, final String libraryName) { if (libraries.contains(libraryName)) { final FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor(false, true, false, false, false, false) { - public Icon getOpenIcon(final VirtualFile virtualFile) { - return looksLikeEclipse(virtualFile) ? eclipseIcon : super.getOpenIcon(virtualFile); + public Icon getOpenIcon(final VirtualFile file) { + return looksLikeEclipse(file) ? dressIcon(file, eclipseIcon) : super.getOpenIcon(file); } - public Icon getClosedIcon(final VirtualFile virtualFile) { - return looksLikeEclipse(virtualFile) ? eclipseIcon : super.getClosedIcon(virtualFile); + public Icon getClosedIcon(final VirtualFile file) { + return looksLikeEclipse(file) ? dressIcon(file, eclipseIcon) : super.getClosedIcon(file); } - private boolean looksLikeEclipse(final VirtualFile virtualFile) { - return virtualFile.findChild(".eclipseproduct") != null; + private boolean looksLikeEclipse(final VirtualFile file) { + return file.findChild(".eclipseproduct") != null; } }; fileChooserDescriptor.setTitle(EclipseBundle.message("eclipse.create.library.title")); From e497b81929851981de70596185be3f455afde0f5 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Thu, 2 Feb 2012 18:09:54 +0100 Subject: [PATCH 37/43] npe fix --- .../intellij/ide/util/FileStructurePopup.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/util/FileStructurePopup.java b/platform/lang-impl/src/com/intellij/ide/util/FileStructurePopup.java index 58ecff594a9c..d438f5388335 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/FileStructurePopup.java +++ b/platform/lang-impl/src/com/intellij/ide/util/FileStructurePopup.java @@ -481,13 +481,16 @@ public class FileStructurePopup implements Disposable { @Nullable private AbstractTreeNode getSelectedNode() { - Object component = myTree.getSelectionPath().getLastPathComponent(); - if (component instanceof DefaultMutableTreeNode) { - component = ((DefaultMutableTreeNode)component).getUserObject(); - if (component instanceof FilteringTreeStructure.FilteringNode) { - component = ((FilteringTreeStructure.FilteringNode)component).getDelegate(); - if (component instanceof AbstractTreeNode) { - return (AbstractTreeNode)component; + final TreePath path = myTree.getSelectionPath(); + if (path != null) { + Object component = path.getLastPathComponent(); + if (component instanceof DefaultMutableTreeNode) { + component = ((DefaultMutableTreeNode)component).getUserObject(); + if (component instanceof FilteringTreeStructure.FilteringNode) { + component = ((FilteringTreeStructure.FilteringNode)component).getDelegate(); + if (component instanceof AbstractTreeNode) { + return (AbstractTreeNode)component; + } } } } From 24ec63e74edd44cb0e6f0d481098720a62098c80 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 2 Feb 2012 21:12:17 +0400 Subject: [PATCH 38/43] iterate over: correct offset to detect template applicability --- .../IterateOverIterableIntention.java | 14 +++++++++ .../quickFix/iterateOver/after1.java | 11 +++++++ .../quickFix/iterateOver/after2.java | 11 +++++++ .../quickFix/iterateOver/before1.java | 6 ++++ .../quickFix/iterateOver/before2.java | 6 ++++ .../daemon/quickFix/IterateOverTest.java | 31 +++++++++++++++++++ 6 files changed, 79 insertions(+) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/iterateOver/after1.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/iterateOver/after2.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/iterateOver/before1.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/iterateOver/before2.java create mode 100644 java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/IterateOverTest.java diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/IterateOverIterableIntention.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/IterateOverIterableIntention.java index 808f30402dbe..514d5f78efaf 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/IterateOverIterableIntention.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/IterateOverIterableIntention.java @@ -51,6 +51,14 @@ public class IterateOverIterableIntention implements IntentionAction { final int selEnd = editor.getSelectionModel().getSelectionEnd(); startOffset = (offset == selStart) ? selEnd : selStart; } + PsiElement element = file.findElementAt(startOffset); + while (element instanceof PsiWhiteSpace) { + element = element.getPrevSibling(); + } + PsiStatement psiStatement = PsiTreeUtil.getParentOfType(element, PsiStatement.class, false); + if (psiStatement != null) { + startOffset = psiStatement.getTextRange().getStartOffset(); + } if (!template.isDeactivated() && (TemplateManagerImpl.isApplicable(file, offset, template) || (TemplateManagerImpl.isApplicable(file, startOffset, template)))) { @@ -97,6 +105,12 @@ public class IterateOverIterableIntention implements IntentionAction { } PsiElement element = file.findElementAt(editor.getCaretModel().getOffset()); + while (element instanceof PsiWhiteSpace) { + element = element.getPrevSibling(); + } + if (element instanceof PsiExpressionStatement) { + element = ((PsiExpressionStatement)element).getExpression().getLastChild(); + } while ((element = PsiTreeUtil.getParentOfType(element, PsiExpression.class, true)) != null) { if (element.getParent() instanceof PsiMethodCallExpression) continue; final PsiType type = ((PsiExpression)element).getType(); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/iterateOver/after1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/iterateOver/after1.java new file mode 100644 index 000000000000..a5873220466d --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/iterateOver/after1.java @@ -0,0 +1,11 @@ +import java.lang.annotation.Annotation; + +// "Iterate" "true" +class Test { + void foo() { + for (Annotation annotation : getClass().getAnnotations()) { + + } + + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/iterateOver/after2.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/iterateOver/after2.java new file mode 100644 index 000000000000..a5873220466d --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/iterateOver/after2.java @@ -0,0 +1,11 @@ +import java.lang.annotation.Annotation; + +// "Iterate" "true" +class Test { + void foo() { + for (Annotation annotation : getClass().getAnnotations()) { + + } + + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/iterateOver/before1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/iterateOver/before1.java new file mode 100644 index 000000000000..d309549f1aa9 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/iterateOver/before1.java @@ -0,0 +1,6 @@ +// "Iterate" "true" +class Test { + void foo() { + getClass().getAnnotations() + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/iterateOver/before2.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/iterateOver/before2.java new file mode 100644 index 000000000000..d0785fb012ad --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/iterateOver/before2.java @@ -0,0 +1,6 @@ +// "Iterate" "true" +class Test { + void foo() { + getClass().getAnnotations() + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/IterateOverTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/IterateOverTest.java new file mode 100644 index 000000000000..17cf0dd8566c --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/IterateOverTest.java @@ -0,0 +1,31 @@ + +/* + * Copyright 2000-2012 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.codeInsight.daemon.quickFix; + + + +public class IterateOverTest extends LightQuickFix15TestCase { + + public void test() throws Exception { doAllTests(); } + + @Override + protected String getBasePath() { + return "/codeInsight/daemonCodeAnalyzer/quickFix/iterateOver"; + } + +} + From a0e7cb5812e6ae378a6ea22380034b003d914875 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 2 Feb 2012 17:13:44 +0100 Subject: [PATCH 39/43] fix lookup start marker invalidation when finishing completion with a char inside a live template --- .../completion/JavaAutoPopupTest.groovy | 13 +++ .../completion/CodeCompletionHandlerBase.java | 2 +- .../lookup/impl/LookupTypedHandler.java | 83 +++++++++++-------- .../command/impl/DocumentUndoProvider.java | 7 +- .../command/impl/EditorChangeAction.java | 13 ++- 5 files changed, 73 insertions(+), 45 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy index 87fef910ec3c..e8b463fa0575 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy @@ -1203,4 +1203,17 @@ class Foo {{ assert myFixture.file.text.contains('FIS:') } + public void testSoutvTemplate() { + ((TemplateManagerImpl)TemplateManager.getInstance(getProject())).setTemplateTesting(true); + try { + myFixture.configureByText 'a.java', 'class Foo {{ }}' + type 'soutv\tgetcl.' + myFixture.checkResult '''class Foo {{ + System.out.println("getClass(). = " + getClass().); }}''' + } + finally { + ((TemplateManagerImpl)TemplateManager.getInstance(getProject())).setTemplateTesting(false); + } + } + } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java index 3bd5e56306ad..901dd3407581 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java @@ -813,7 +813,7 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler { } } - public static Runnable rememberDocumentState(final Editor _editor) { + private static Runnable rememberDocumentState(final Editor _editor) { final Editor editor = InjectedLanguageUtil.getTopLevelEditor(_editor); final String documentText = editor.getDocument().getText(); final int caret = editor.getCaretModel().getOffset(); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupTypedHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupTypedHandler.java index ae06c5012d1b..61e8e23eafd9 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupTypedHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupTypedHandler.java @@ -32,6 +32,7 @@ import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.command.CommandProcessorEx; +import com.intellij.openapi.command.impl.EditorChangeAction; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorModificationUtil; @@ -42,15 +43,12 @@ import com.intellij.openapi.editor.ex.ScrollingModelEx; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Pair; import com.intellij.psi.PsiFile; -import com.intellij.psi.impl.DebugUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; import java.util.Arrays; -import java.util.List; +import java.util.LinkedList; public class LookupTypedHandler extends TypedHandlerDelegate { private static boolean inside = false; @@ -117,11 +115,7 @@ public class LookupTypedHandler extends TypedHandlerDelegate { inside = false; ((CommandProcessorEx)CommandProcessor.getInstance()).enterModal(); try { - finishLookup(charTyped, lookup, new Runnable() { - public void run() { - EditorModificationUtil.typeInStringAtCaretHonorBlockSelection(editor, String.valueOf(charTyped), true); - } - }); + finishLookup(charTyped, lookup); } finally { ((CommandProcessorEx)CommandProcessor.getInstance()).leaveModal(); @@ -161,45 +155,22 @@ public class LookupTypedHandler extends TypedHandlerDelegate { return false; } - public static void finishLookup(final char charTyped, @NotNull final LookupImpl lookup, final Runnable baseChange) { - Editor editor = lookup.getEditor(); + private static void finishLookup(final char charTyped, @NotNull final LookupImpl lookup) { + final Editor editor = lookup.getEditor(); FeatureUsageTracker.getInstance().triggerFeatureUsed(CodeCompletionFeatures.EDITING_COMPLETION_FINISH_BY_DOT_ETC); CompletionProcess process = CompletionService.getCompletionService().getCurrentCompletion(); SelectionModel sm = editor.getSelectionModel(); final boolean smartUndo = !sm.hasSelection() && !sm.hasBlockSelection() && process != null && process.isAutopopupCompletion(); - final Runnable restore = CodeCompletionHandlerBase.rememberDocumentState(editor); final ScrollingModelEx scrollingModel = (ScrollingModelEx)editor.getScrollingModel(); scrollingModel.accumulateViewportChanges(); try { - final List> events = new ArrayList>(); - final DocumentAdapter listener = new DocumentAdapter() { - @Override - public void documentChanged(DocumentEvent e) { - events.add(Pair.create(e, DebugUtil.currentStackTrace())); - } - }; - editor.getDocument().addDocumentListener(listener); - if (smartUndo) { - CommandProcessor.getInstance().executeCommand(editor.getProject(), new Runnable() { - @Override - public void run() { - lookup.performGuardedChange(baseChange); - } - }, null, "Just insert the completion char"); - } - editor.getDocument().removeDocumentListener(listener); + final LinkedList events = smartUndo ? justTypeChar(charTyped, lookup, editor) : null; CommandProcessor.getInstance().executeCommand(editor.getProject(), new Runnable() { @Override public void run() { if (smartUndo) { - AccessToken token = WriteAction.start(); - try { - lookup.performGuardedChange(restore, events.toString()); - } - finally { - token.finish(); - } + undoEvents(lookup, events); } lookup.finishLookup(charTyped); } @@ -210,6 +181,46 @@ public class LookupTypedHandler extends TypedHandlerDelegate { } } + private static void undoEvents(LookupImpl lookup, @NotNull final LinkedList events) { + AccessToken token = WriteAction.start(); + try { + lookup.performGuardedChange(new Runnable() { + @Override + public void run() { + for (EditorChangeAction event : events) { + event.performUndo(); + } + } + }, events.toString()); + } + finally { + token.finish(); + } + } + + private static LinkedList justTypeChar(final char charTyped, final LookupImpl lookup, final Editor editor) { + final LinkedList events = new LinkedList(); + final DocumentAdapter listener = new DocumentAdapter() { + @Override + public void documentChanged(DocumentEvent e) { + events.addFirst(new EditorChangeAction(e)); + } + }; + editor.getDocument().addDocumentListener(listener); + CommandProcessor.getInstance().executeCommand(editor.getProject(), new Runnable() { + @Override + public void run() { + lookup.performGuardedChange(new Runnable() { + public void run() { + EditorModificationUtil.typeInStringAtCaretHonorBlockSelection(editor, String.valueOf(charTyped), true); + } + }); + } + }, null, "Just insert the completion char"); + editor.getDocument().removeDocumentListener(listener); + return events; + } + static CharFilter.Result getLookupAction(final char charTyped, final LookupImpl lookup) { final CharFilter.Result filtersDecision = getFiltersDecision(charTyped, lookup); diff --git a/platform/platform-impl/src/com/intellij/openapi/command/impl/DocumentUndoProvider.java b/platform/platform-impl/src/com/intellij/openapi/command/impl/DocumentUndoProvider.java index 6524d895638a..9683407b1d41 100644 --- a/platform/platform-impl/src/com/intellij/openapi/command/impl/DocumentUndoProvider.java +++ b/platform/platform-impl/src/com/intellij/openapi/command/impl/DocumentUndoProvider.java @@ -27,7 +27,6 @@ import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorFactory; import com.intellij.openapi.editor.event.DocumentAdapter; import com.intellij.openapi.editor.event.DocumentEvent; -import com.intellij.openapi.editor.ex.DocumentEx; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Key; @@ -108,11 +107,7 @@ public class DocumentUndoProvider implements Disposable { } private void registerUndoableAction(DocumentEvent e) { - getUndoManager().undoableActionPerformed(new EditorChangeAction((DocumentEx)e.getDocument(), - e.getOffset(), - e.getOldFragment(), - e.getNewFragment(), - e.getOldTimeStamp())); + getUndoManager().undoableActionPerformed(new EditorChangeAction(e)); } private void registerNonUndoableAction(final Document document) { diff --git a/platform/platform-impl/src/com/intellij/openapi/command/impl/EditorChangeAction.java b/platform/platform-impl/src/com/intellij/openapi/command/impl/EditorChangeAction.java index e88d4b633896..32efab447f23 100644 --- a/platform/platform-impl/src/com/intellij/openapi/command/impl/EditorChangeAction.java +++ b/platform/platform-impl/src/com/intellij/openapi/command/impl/EditorChangeAction.java @@ -16,6 +16,7 @@ package com.intellij.openapi.command.impl; import com.intellij.openapi.command.undo.BasicUndoableAction; +import com.intellij.openapi.editor.event.DocumentEvent; import com.intellij.openapi.editor.ex.DocumentEx; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManager; @@ -25,13 +26,17 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.testFramework.LightVirtualFile; import org.jetbrains.annotations.NonNls; -class EditorChangeAction extends BasicUndoableAction { +public class EditorChangeAction extends BasicUndoableAction { private final int myOffset; private final CharSequence myOldString; private final CharSequence myNewString; private final long myOldTimeStamp; private final long myNewTimeStamp; + public EditorChangeAction(DocumentEvent e) { + this((DocumentEx)e.getDocument(), e.getOffset(), e.getOldFragment(), e.getNewFragment(), e.getOldTimeStamp()); + } + public EditorChangeAction(DocumentEx document, int offset, CharSequence oldString, @@ -49,7 +54,7 @@ class EditorChangeAction extends BasicUndoableAction { public void undo() { DocumentUndoProvider.startDocumentUndo(getDocument()); try { - exchangeStrings(myNewString, myOldString); + performUndo(); } finally { DocumentUndoProvider.finishDocumentUndo(getDocument()); @@ -59,6 +64,10 @@ class EditorChangeAction extends BasicUndoableAction { refreshFileStatus(); } + public void performUndo() { + exchangeStrings(myNewString, myOldString); + } + public void redo() { DocumentUndoProvider.startDocumentUndo(getDocument()); try { From 0b2017edd9b6feedd5aac23826fcfb47ab95409f Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 2 Feb 2012 17:54:22 +0100 Subject: [PATCH 40/43] when lookup start offset is corrupted, hide it to prevent further exceptions --- .../lookup/impl/BackspaceHandler.java | 6 +++-- .../lookup/impl/LookupActionHandler.java | 12 ++++++--- .../codeInsight/lookup/impl/LookupImpl.java | 25 ++++++++++++------ .../lookup/impl/LookupTypedHandler.java | 26 ++++++++++++------- 4 files changed, 46 insertions(+), 23 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/BackspaceHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/BackspaceHandler.java index 5087e8a4e055..6075d795e216 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/BackspaceHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/BackspaceHandler.java @@ -42,12 +42,14 @@ public class BackspaceHandler extends EditorActionHandler { static void truncatePrefix(final DataContext dataContext, LookupImpl lookup, final EditorActionHandler handler, final int hideOffset) { final Editor editor = lookup.getEditor(); - lookup.performGuardedChange(new Runnable() { + if (!lookup.performGuardedChange(new Runnable() { @Override public void run() { handler.execute(editor, dataContext); } - }); + })) { + return; + } final CompletionProgressIndicator process = CompletionServiceImpl.getCompletionService().getCurrentCompletion(); if (lookup.truncatePrefix(process == null || !process.isAutopopupCompletion())) { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupActionHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupActionHandler.java index f9949aa86f96..aa3f9ca8eceb 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupActionHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupActionHandler.java @@ -187,12 +187,14 @@ public abstract class LookupActionHandler extends EditorActionHandler { return; } - lookup.performGuardedChange(new Runnable() { + if (!lookup.performGuardedChange(new Runnable() { @Override public void run() { lookup.getEditor().getSelectionModel().removeSelection(); } - }); + })) { + return; + } BackspaceHandler.truncatePrefix(context, lookup, myOriginalHandler, lookup.getLookupStart() - 1); } @@ -220,13 +222,15 @@ public abstract class LookupActionHandler extends EditorActionHandler { return; } - lookup.performGuardedChange(new Runnable() { + if (!lookup.performGuardedChange(new Runnable() { @Override public void run() { editor.getSelectionModel().removeSelection(); editor.getCaretModel().moveToOffset(offset + 1); } - }); + })) { + return; + } lookup.appendPrefix(c); final CompletionProgressIndicator completion = CompletionServiceImpl.getCompletionService().getCurrentCompletion(); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java index d3701d44719c..70868e78e874 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java @@ -741,8 +741,8 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable if (!plainMatch) { FeatureUsageTracker.getInstance().triggerFeatureUsed(CodeCompletionFeatures.EDITING_COMPLETION_CAMEL_HUMPS); } - - performGuardedChange(new Runnable() { + + if (!performGuardedChange(new Runnable() { public void run() { AccessToken token = WriteAction.start(); try { @@ -752,7 +752,9 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable token.finish(); } } - }); + })) { + return; + } doHide(false, true); @@ -828,11 +830,11 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable return myLookupStartMarker.getStartOffset(); } - public void performGuardedChange(Runnable change) { - performGuardedChange(change, null); + public boolean performGuardedChange(Runnable change) { + return performGuardedChange(change, null); } - public void performGuardedChange(Runnable change, @Nullable final String debug) { + public boolean performGuardedChange(Runnable change, @Nullable final String debug) { checkValid(); assert myLookupStartMarker.isValid(); assert !myChangeGuard; @@ -855,12 +857,17 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable document.removeDocumentListener(spy); myChangeGuard = false; } + if (!myLookupStartMarker.isValid()) { + hide(); + return false; + } checkValid(); LOG.assertTrue(myLookupStartMarker.isValid(), "invalid lookup start"); if (isVisible()) { updateLookupLocation(); } checkValid(); + return true; } @Override @@ -1185,7 +1192,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable } public void replacePrefix(final String presentPrefix, final String newPrefix) { - performGuardedChange(new Runnable() { + if (!performGuardedChange(new Runnable() { public void run() { EditorModificationUtil.deleteSelectedText(myEditor); int offset = myEditor.getCaretModel().getOffset(); @@ -1200,7 +1207,9 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable myEditor.getCaretModel().moveToOffset(start + newPrefix.length()); } - }); + })) { + return; + } refreshUi(true); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupTypedHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupTypedHandler.java index 61e8e23eafd9..3c875a20d9c3 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupTypedHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupTypedHandler.java @@ -53,6 +53,7 @@ import java.util.LinkedList; public class LookupTypedHandler extends TypedHandlerDelegate { private static boolean inside = false; + @SuppressWarnings("AssignmentToStaticFieldFromInstanceMethod") @Override public Result beforeCharTyped(final char charTyped, Project project, @@ -72,20 +73,24 @@ public class LookupTypedHandler extends TypedHandlerDelegate { } final CharFilter.Result result = getLookupAction(charTyped, lookup); - lookup.performGuardedChange(new Runnable() { + if (!lookup.performGuardedChange(new Runnable() { public void run() { EditorModificationUtil.deleteSelectedText(editor); } - }); + })) { + return Result.STOP; + } if (result == CharFilter.Result.ADD_TO_PREFIX) { Document document = editor.getDocument(); long modificationStamp = document.getModificationStamp(); - lookup.performGuardedChange(new Runnable() { + if (!lookup.performGuardedChange(new Runnable() { public void run() { EditorModificationUtil.typeInStringAtCaretHonorBlockSelection(editor, String.valueOf(charTyped), true); } - }); + })) { + return Result.STOP; + } lookup.appendPrefix(charTyped); if (lookup.isStartCompletionWhenNothingMatches() && lookup.getItems().isEmpty()) { final CompletionProgressIndicator completion = CompletionServiceImpl.getCompletionService().getCurrentCompletion(); @@ -132,7 +137,7 @@ public class LookupTypedHandler extends TypedHandlerDelegate { } } - private boolean completeTillTypedCharOccurrence(char charTyped, LookupImpl lookup, LookupElement item) { + private static boolean completeTillTypedCharOccurrence(char charTyped, LookupImpl lookup, LookupElement item) { PrefixMatcher matcher = lookup.itemMatcher(item); final String oldPrefix = matcher.getPrefix() + lookup.getAdditionalPrefix(); PrefixMatcher expanded = matcher.cloneWithPrefix(oldPrefix + charTyped); @@ -165,12 +170,15 @@ public class LookupTypedHandler extends TypedHandlerDelegate { scrollingModel.accumulateViewportChanges(); try { final LinkedList events = smartUndo ? justTypeChar(charTyped, lookup, editor) : null; + if (lookup.isLookupDisposed()) { // if justTypeChar corrupted the start offset + return; + } CommandProcessor.getInstance().executeCommand(editor.getProject(), new Runnable() { @Override public void run() { - if (smartUndo) { - undoEvents(lookup, events); + if (smartUndo && !undoEvents(lookup, events)) { + return; } lookup.finishLookup(charTyped); } @@ -181,10 +189,10 @@ public class LookupTypedHandler extends TypedHandlerDelegate { } } - private static void undoEvents(LookupImpl lookup, @NotNull final LinkedList events) { + private static boolean undoEvents(LookupImpl lookup, @NotNull final LinkedList events) { AccessToken token = WriteAction.start(); try { - lookup.performGuardedChange(new Runnable() { + return lookup.performGuardedChange(new Runnable() { @Override public void run() { for (EditorChangeAction event : events) { From 7d54095cce8c4067064308eae487753fa62623f5 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 2 Feb 2012 17:57:34 +0100 Subject: [PATCH 41/43] when lookup is hidden during guarded change, don't proceed --- .../src/com/intellij/codeInsight/lookup/impl/LookupImpl.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java index 70868e78e874..b0002cfa6d31 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java @@ -857,12 +857,10 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable document.removeDocumentListener(spy); myChangeGuard = false; } - if (!myLookupStartMarker.isValid()) { + if (!myLookupStartMarker.isValid() || myDisposed) { hide(); return false; } - checkValid(); - LOG.assertTrue(myLookupStartMarker.isValid(), "invalid lookup start"); if (isVisible()) { updateLookupLocation(); } From d4a1214f7868568530d8ad4155f3ce056952f291 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 2 Feb 2012 18:06:10 +0100 Subject: [PATCH 42/43] accept that lookup listeners sometimes close lookups (EA-33437) --- .../src/com/intellij/codeInsight/lookup/impl/LookupImpl.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java index b0002cfa6d31..462518d7a9ca 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java @@ -978,6 +978,9 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable if (oldItem != item) { mySelectionInvariant = item == null ? null : myPresentableModel.getItemPresentationInvariant(item); fireCurrentItemChanged(item); + if (myDisposed) { //a listener may have decided to close us, what can we do? + return; + } } if (item != null) { updateHint(item); From 07666225ec486c06c1e975a4db0686b249bc363d Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 2 Feb 2012 18:55:39 +0100 Subject: [PATCH 43/43] tolerate lookup being closed by 3d parties during finishLookup (EA-33434,EA-32899) --- .../codeInsight/lookup/impl/LookupImpl.java | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java index 462518d7a9ca..31f9663f145e 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java @@ -137,6 +137,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable private boolean myStartCompletionWhenNothingMatches; private boolean myResizePending; private int myMaximumHeight = Integer.MAX_VALUE; + private boolean myFinishing; public LookupImpl(Project project, Editor editor, @NotNull LookupArranger arranger){ super(new JPanel(new BorderLayout())); @@ -714,6 +715,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable } public void finishLookup(char completionChar, @Nullable final LookupElement item) { + //noinspection deprecation,unchecked if (item == null || item instanceof EmptyLookupItem || item.getObject() instanceof DeferredUserLookupValue && @@ -724,6 +726,10 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable return; } + if (myDisposed) { // DeferredUserLookupValue could close us in any way + return; + } + final PsiFile file = getPsiFile(); if (file != null && !WriteCommandAction.ensureFilesWritable(myProject, Arrays.asList(file))) { doHide(false, true); @@ -731,6 +737,10 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable return; } + if (myDisposed) { // ensureFilesWritable could close us by showing a dialog + return; + } + final String prefix = itemPattern(item); boolean plainMatch = ContainerUtil.or(item.getAllLookupStrings(), new Condition() { @Override @@ -742,17 +752,16 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable FeatureUsageTracker.getInstance().triggerFeatureUsed(CodeCompletionFeatures.EDITING_COMPLETION_CAMEL_HUMPS); } - if (!performGuardedChange(new Runnable() { - public void run() { - AccessToken token = WriteAction.start(); - try { - insertLookupString(item, prefix); - } - finally { - token.finish(); - } - } - })) { + myFinishing = true; + AccessToken token = WriteAction.start(); + try { + insertLookupString(item, prefix); + } + finally { + token.finish(); + } + + if (myDisposed) { // any document listeners could close us return; } @@ -929,7 +938,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable private void addListeners() { myEditor.getDocument().addDocumentListener(new DocumentAdapter() { public void documentChanged(DocumentEvent e) { - if (!myChangeGuard) { + if (!myChangeGuard && !myFinishing) { hide(); } } @@ -937,14 +946,14 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable final CaretListener caretListener = new CaretListener() { public void caretPositionChanged(CaretEvent e) { - if (!myChangeGuard) { + if (!myChangeGuard && !myFinishing) { hide(); } } }; final SelectionListener selectionListener = new SelectionListener() { public void selectionChanged(final SelectionEvent e) { - if (!myChangeGuard) { + if (!myChangeGuard && !myFinishing) { hide(); } }