diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/MarkerType.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/MarkerType.java index 640fafc0f609..c2817d2f8672 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/MarkerType.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/MarkerType.java @@ -245,7 +245,7 @@ public class MarkerType { } @Override - public void run(@NotNull ProgressIndicator indicator) { + public void run(@NotNull final ProgressIndicator indicator) { super.run(indicator); ClassInheritorsSearch.search(myClass, ApplicationManager.getApplication().runReadAction(new Computable() { @Override @@ -255,7 +255,10 @@ public class MarkerType { }), true).forEach(new CommonProcessors.CollectProcessor() { @Override public boolean process(final PsiClass o) { - updateComponent(o, myRenderer.getComparator()); + if (!updateComponent(o, myRenderer.getComparator())) { + indicator.cancel(); + } + indicator.checkCanceled(); return super.process(o); } }); @@ -281,13 +284,16 @@ public class MarkerType { } @Override - public void run(@NotNull ProgressIndicator indicator) { + public void run(@NotNull final ProgressIndicator indicator) { super.run(indicator); OverridingMethodsSearch.search(myMethod, true).forEach( new CommonProcessors.CollectProcessor() { @Override public boolean process(PsiMethod psiMethod) { - updateComponent(psiMethod, myRenderer.getComparator()); + if (!updateComponent(psiMethod, myRenderer.getComparator())) { + indicator.cancel(); + } + indicator.checkCanceled(); return super.process(psiMethod); } }); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/hint/actions/ShowImplementationsAction.java b/platform/lang-impl/src/com/intellij/codeInsight/hint/actions/ShowImplementationsAction.java index 99efaf5e9d08..1f0d80bc1f16 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/hint/actions/ShowImplementationsAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/hint/actions/ShowImplementationsAction.java @@ -335,13 +335,16 @@ public class ShowImplementationsAction extends AnAction implements PopupAction { } @Override - public void run(@NotNull ProgressIndicator indicator) { + public void run(final @NotNull ProgressIndicator indicator) { super.run(indicator); myElements = getSelfAndImplementations(myEditor, myElement, new ImplementationSearcher.BackgroundableImplementationSearcher() { @Override protected void processElement(PsiElement element) { - updateComponent(element, null); + if (!updateComponent(element, null)) { + indicator.cancel(); + } + indicator.checkCanceled(); } @Override diff --git a/platform/lang-impl/src/com/intellij/codeInsight/navigation/BackgroundUpdaterTask.java b/platform/lang-impl/src/com/intellij/codeInsight/navigation/BackgroundUpdaterTask.java index 2490267051e0..4c1dd1bf8777 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/navigation/BackgroundUpdaterTask.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/navigation/BackgroundUpdaterTask.java @@ -83,12 +83,12 @@ public abstract class BackgroundUpdaterTask extends Task.Backgroundable { return canceled; } - public void updateComponent(PsiElement element, @Nullable final Comparator comparator) { - if (myCanceled) return; - if (myPopup.isDisposed()) return; + public boolean updateComponent(PsiElement element, @Nullable final Comparator comparator) { + if (myCanceled) return false; + if (myPopup.isDisposed()) return false; synchronized (lock) { - if (myData.contains(element)) return; + if (myData.contains(element)) return true; myData.add(element); } @@ -110,6 +110,7 @@ public abstract class BackgroundUpdaterTask extends Task.Backgroundable { myPopup.pack(true, true); } }, 200, ModalityState.stateForComponent(myPopup.getContent())); + return true; } public int getCurrentSize() { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/navigation/GotoImplementationHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/navigation/GotoImplementationHandler.java index 14be963ab4bb..11ee1c156d9e 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/navigation/GotoImplementationHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/navigation/GotoImplementationHandler.java @@ -78,16 +78,21 @@ public class GotoImplementationHandler extends GotoTargetHandler { } @Override - public void run(@NotNull ProgressIndicator indicator) { + public void run(final @NotNull ProgressIndicator indicator) { super.run(indicator); for (PsiElement element : myGotoData.targets) { - updateComponent(element, createComparator(renderers, myGotoData)); + if (!updateComponent(element, createComparator(renderers, myGotoData))) { + return; + } } new ImplementationSearcher.BackgroundableImplementationSearcher() { protected void processElement(PsiElement element) { if (myGotoData.addTarget(element)) { - updateComponent(element, createComparator(renderers, myGotoData)); + if (!updateComponent(element, createComparator(renderers, myGotoData))) { + indicator.cancel(); + } } + indicator.checkCanceled(); } }.searchImplementations(myEditor, myGotoData.source, myOffset); } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java index 6da46cf1adec..6cbbba6a4c2b 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java @@ -426,11 +426,15 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel, } public void disableToolByDefault(String toolId) { - getTools(toolId).getDefaultState().setEnabled(false); + getToolDefaultState(toolId).setEnabled(false); + } + + public ScopeToolState getToolDefaultState(String toolId) { + return getTools(toolId).getDefaultState(); } public void enableToolByDefault(String toolId) { - getTools(toolId).getDefaultState().setEnabled(true); + getToolDefaultState(toolId).setEnabled(true); } public boolean wasInitialized() { diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/impl/RootModelImpl.java b/platform/lang-impl/src/com/intellij/openapi/roots/impl/RootModelImpl.java index 139a086701f0..7978065cd240 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/impl/RootModelImpl.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/RootModelImpl.java @@ -82,7 +82,15 @@ public class RootModelImpl implements ModifiableRootModel { @NonNls private static final String ROOT_ELEMENT = "root"; private final ProjectRootManagerImpl myProjectRootManager; // have to register all child disposables using this fake object since all clients call just ModifiableModel.dispose() - private final Disposable myDisposable = Disposer.newDisposable(); + private final List myModelComponents = Collections.synchronizedList(new ArrayList()); + private final Disposable myDisposable = new Disposable() { + @Override + public void dispose() { + for (Disposable component : myModelComponents) { + Disposer.dispose(component); + } + } + }; RootModelImpl(@NotNull ModuleRootManagerImpl moduleRootManager, ProjectRootManagerImpl projectRootManager, VirtualFilePointerManager filePointerManager) { myModuleRootManager = moduleRootManager; @@ -96,7 +104,7 @@ public class RootModelImpl implements ModifiableRootModel { for (ModuleExtension extension : Extensions.getExtensions(ModuleExtension.EP_NAME, moduleRootManager.getModule())) { ModuleExtension model = extension.getModifiableModel(false); - Disposer.register(myDisposable, model); + registerOnDispose(model); myExtensions.add(model); } myConfigurationAccessor = new RootConfigurationAccessor(); @@ -162,7 +170,7 @@ public class RootModelImpl implements ModifiableRootModel { for (ModuleExtension extension : originalRootModel.myExtensions) { ModuleExtension model = extension.getModifiableModel(false); model.readExternal(element); - Disposer.register(myDisposable, model); + registerOnDispose(model); myExtensions.add(model); } myConfigurationAccessor = new RootConfigurationAccessor(); @@ -207,7 +215,7 @@ public class RootModelImpl implements ModifiableRootModel { for (ModuleExtension extension : rootModel.myExtensions) { ModuleExtension model = extension.getModifiableModel(writable); - Disposer.register(myDisposable, model); + registerOnDispose(model); myExtensions.add(model); } } @@ -912,6 +920,7 @@ public class RootModelImpl implements ModifiableRootModel { myExtensions.clear(); myWritable = false; myDisposed = true; + myModelComponents.clear(); } @Override @@ -1139,6 +1148,6 @@ public class RootModelImpl implements ModifiableRootModel { } void registerOnDispose(@NotNull Disposable disposable) { - Disposer.register(myDisposable, disposable); + myModelComponents.add(disposable); } } diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/SingleInspectionProfilePanel.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/SingleInspectionProfilePanel.java index ba2c682d3ecf..3fd374b320bf 100644 --- a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/SingleInspectionProfilePanel.java +++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/SingleInspectionProfilePanel.java @@ -1048,29 +1048,13 @@ public class SingleInspectionProfilePanel extends JPanel { for (int i = 0; rows != null && i < rows.length; i++) { final InspectionConfigTreeNode node = (InspectionConfigTreeNode)myTree.getPathForRow(rows[i]).getLastPathComponent(); final InspectionConfigTreeNode parent = (InspectionConfigTreeNode)node.getParent(); - if (node.getUserObject() instanceof Descriptor) { + final Object userObject = node.getUserObject(); + if (userObject instanceof Descriptor && (node.getScopeName() != null || node.isLeaf())) { updateErrorLevel(node, showOptionsAndDescriptorPanels, level); updateUpHierarchy(node, parent); } else { - node.isProperSetting = false; - for (int j = 0; j < node.getChildCount(); j++) { - final InspectionConfigTreeNode child = (InspectionConfigTreeNode)node.getChildAt(j); - if (child.getUserObject() instanceof Descriptor) { //group node - updateErrorLevel(child, showOptionsAndDescriptorPanels, level); - } - else { //root node - child.isProperSetting = false; - for (int k = 0; k < child.getChildCount(); k++) { - final InspectionConfigTreeNode descriptorNode = (InspectionConfigTreeNode)child.getChildAt(k); - if (descriptorNode.getUserObject() instanceof Descriptor) { - updateErrorLevel(descriptorNode, showOptionsAndDescriptorPanels, level); - } - child.isProperSetting |= descriptorNode.isProperSetting; - } - } - node.isProperSetting |= child.isProperSetting; - } + updateErrorLevelUpInHierarchy(level, showOptionsAndDescriptorPanels, node); updateUpHierarchy(node, parent); } } @@ -1083,6 +1067,23 @@ public class SingleInspectionProfilePanel extends JPanel { repaintTableData(); } + private void updateErrorLevelUpInHierarchy(HighlightDisplayLevel level, + boolean showOptionsAndDescriptorPanels, + InspectionConfigTreeNode node) { + node.isProperSetting = false; + for (int j = 0; j < node.getChildCount(); j++) { + final InspectionConfigTreeNode child = (InspectionConfigTreeNode)node.getChildAt(j); + final Object userObject = child.getUserObject(); + if (userObject instanceof Descriptor && (child.getScopeName() != null || child.isLeaf())) { + updateErrorLevel(child, showOptionsAndDescriptorPanels, level); + } + else { + updateErrorLevelUpInHierarchy(level, showOptionsAndDescriptorPanels, child); + } + node.isProperSetting |= child.isProperSetting; + } + } + private void updateErrorLevel(final InspectionConfigTreeNode child, final boolean showOptionsAndDescriptorPanels, final HighlightDisplayLevel level) { final HighlightDisplayKey key = child.getDesriptor().getKey(); diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/actions/AddScopeAction.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/actions/AddScopeAction.java index ccc3f0817d40..67c9e658c90b 100644 --- a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/actions/AddScopeAction.java +++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/actions/AddScopeAction.java @@ -59,13 +59,11 @@ public abstract class AddScopeAction extends AnAction { if (getSelectedProfile() == null) return; final Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext()); if (project == null) return; - final InspectionConfigTreeNode[] nodes = myTree.getSelectedNodes(InspectionConfigTreeNode.class, null); + final InspectionConfigTreeNode[] selectedNodes = myTree.getSelectedNodes(InspectionConfigTreeNode.class, null); + if (selectedNodes == null) return; final List descriptors = new ArrayList(); - for (InspectionConfigTreeNode node : nodes) { - final Descriptor descriptor = node.getDesriptor(); - if (descriptor != null && node.getScopeName() == null) { - descriptors.add(descriptor); - } + for (InspectionConfigTreeNode node : selectedNodes) { + collect(descriptors, new ArrayList(), node); } presentation.setEnabled(!getAvailableScopes(project, descriptors).isEmpty()); @@ -73,13 +71,13 @@ public abstract class AddScopeAction extends AnAction { @Override public void actionPerformed(AnActionEvent e) { - final InspectionConfigTreeNode[] nodes = myTree.getSelectedNodes(InspectionConfigTreeNode.class, null); - List descriptors = new ArrayList(); - for (InspectionConfigTreeNode node : nodes) { - final Descriptor descriptor = node.getDesriptor(); - if (node.getScopeName() == null && descriptor != null) { - descriptors.add(descriptor); - } + final List descriptors = new ArrayList(); + final InspectionConfigTreeNode[] selectedNodes = myTree.getSelectedNodes(InspectionConfigTreeNode.class, null); + LOG.assertTrue(selectedNodes != null); + + final List nodes = new ArrayList(Arrays.asList(selectedNodes)); + for (InspectionConfigTreeNode node : selectedNodes) { + collect(descriptors, nodes, node); } final Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext()); @@ -97,7 +95,7 @@ public abstract class AddScopeAction extends AnAction { getSelectedProfile().isToolEnabled(descriptor.getKey())); final Descriptor addedDescriptor = new Descriptor(scopeToolState, getSelectedProfile()); if (node.getChildCount() == 0) { - node.add(new InspectionConfigTreeNode(descriptor, scopeToolState, true, true, false)); + node.add(new InspectionConfigTreeNode(descriptor, getSelectedProfile().getToolDefaultState(descriptor.getKey().getID()), true, true, false)); } node.insert(new InspectionConfigTreeNode(addedDescriptor, scopeToolState, false, true, false), 0); node.setInspectionNode(false); @@ -108,6 +106,23 @@ public abstract class AddScopeAction extends AnAction { myTree.revalidate(); } + private static void collect(List descriptors, + List nodes, + InspectionConfigTreeNode node) { + final Descriptor descriptor = node.getDesriptor(); + if (descriptor != null) { + if (node.getScopeName() == null) { + descriptors.add(descriptor); + } + } else if (node.getUserObject() instanceof String) { + for(int i = 0; i < node.getChildCount(); i++) { + final InspectionConfigTreeNode childNode = (InspectionConfigTreeNode)node.getChildAt(i); + nodes.add(childNode); + collect(descriptors, nodes, childNode); + } + } + } + private List getAvailableScopes(Project project, List descriptors) { final ArrayList scopes = new ArrayList(); for (NamedScopesHolder holder : NamedScopesHolder.getAllNamedScopeHolders(project)) { diff --git a/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/MasterKeyPasswordSafe.java b/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/MasterKeyPasswordSafe.java index 5a516066e7b7..82fad28a4996 100644 --- a/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/MasterKeyPasswordSafe.java +++ b/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/MasterKeyPasswordSafe.java @@ -22,10 +22,10 @@ import com.intellij.ide.passwordSafe.impl.providers.ByteArrayWrapper; import com.intellij.ide.passwordSafe.impl.providers.EncryptionUtil; import com.intellij.ide.passwordSafe.impl.providers.masterKey.windows.WindowsCryptUtils; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.SystemInfo; -import com.intellij.util.WaitForProgressToShow; import java.io.UnsupportedEncodingException; import java.util.HashMap; @@ -182,7 +182,7 @@ public class MasterKeyPasswordSafe extends BasePasswordSafeProvider { } if (key.get() == null) { final Ref ex = new Ref(); - WaitForProgressToShow.runOrInvokeAndWaitAboveProgress(new Runnable() { + ApplicationManager.getApplication().invokeAndWait(new Runnable() { public void run() { if (key.get() == null) { try { @@ -207,7 +207,7 @@ public class MasterKeyPasswordSafe extends BasePasswordSafeProvider { } } } - }); + }, ModalityState.NON_MODAL); //noinspection ThrowableResultOfMethodCallIgnored if (ex.get() != null) { throw ex.get(); diff --git a/platform/platform-impl/src/com/intellij/ide/passwordSafe/ui/PasswordSafePromptDialog.java b/platform/platform-impl/src/com/intellij/ide/passwordSafe/ui/PasswordSafePromptDialog.java index d83651858622..21254efc1ba6 100644 --- a/platform/platform-impl/src/com/intellij/ide/passwordSafe/ui/PasswordSafePromptDialog.java +++ b/platform/platform-impl/src/com/intellij/ide/passwordSafe/ui/PasswordSafePromptDialog.java @@ -18,6 +18,8 @@ package com.intellij.ide.passwordSafe.ui; import com.intellij.ide.passwordSafe.PasswordSafe; import com.intellij.ide.passwordSafe.PasswordSafeException; import com.intellij.ide.passwordSafe.impl.PasswordSafeImpl; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; @@ -271,7 +273,7 @@ public class PasswordSafePromptDialog extends DialogWrapper { } } final AtomicReference pw = new AtomicReference(null); - UIUtil.invokeAndWaitIfNeeded(new Runnable() { + ApplicationManager.getApplication().invokeAndWait(new Runnable() { public void run() { final PasswordSafePromptDialog d = new PasswordSafePromptDialog(project, ps, title, message); if (promptLabel != null) { @@ -299,7 +301,7 @@ public class PasswordSafePromptDialog extends DialogWrapper { } } } - }); + }, ModalityState.NON_MODAL); return pw.get(); } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/pending/DuringChangeListManagerUpdateTestScheme.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/pending/DuringChangeListManagerUpdateTestScheme.java index fe4295ba504b..578ac75d7999 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/pending/DuringChangeListManagerUpdateTestScheme.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/pending/DuringChangeListManagerUpdateTestScheme.java @@ -129,6 +129,10 @@ public class DuringChangeListManagerUpdateTestScheme { } public static void checkFilesAreInList(final VirtualFile[] files, final String listName, final ChangeListManager manager) { + checkFilesAreInList(listName, manager, files); + } + + public static void checkFilesAreInList(final String listName, final ChangeListManager manager, final VirtualFile... files) { System.out.println("Checking files for list: " + listName); assert manager.findChangeList(listName) != null; final LocalChangeList list = manager.findChangeList(listName); diff --git a/plugins/git4idea/src/git4idea/repo/GitRepositoryManagerImpl.java b/plugins/git4idea/src/git4idea/repo/GitRepositoryManagerImpl.java index b88de0d1f5d2..6975469ef6e1 100644 --- a/plugins/git4idea/src/git4idea/repo/GitRepositoryManagerImpl.java +++ b/plugins/git4idea/src/git4idea/repo/GitRepositoryManagerImpl.java @@ -144,22 +144,21 @@ public class GitRepositoryManagerImpl extends AbstractProjectComponent implement // note: we are not calling this method during the project startup - it is called anyway by the GitRootTracker private void updateRepositoriesCollection() { - try { - REPO_LOCK.writeLock().lock(); + Map repositories = new HashMap(myRepositories); final VirtualFile[] roots = myVcsManager.getRootsUnderVcs(myVcs); // remove repositories that are not in the roots anymore - for (Iterator> iterator = myRepositories.entrySet().iterator(); iterator.hasNext(); ) { + for (Iterator> iterator = repositories.entrySet().iterator(); iterator.hasNext(); ) { if (!ArrayUtil.contains(iterator.next().getValue().getRoot(), roots)) { iterator.remove(); } } // add GitRepositories for all roots that don't have correspondent GitRepositories yet. for (VirtualFile root : roots) { - if (!myRepositories.containsKey(root)) { + if (!repositories.containsKey(root)) { if (gitRootOK(root)) { try { GitRepository repository = createGitRepository(root); - myRepositories.put(root, repository); + repositories.put(root, repository); } catch (GitRepoStateException e) { LOG.error("Couldn't initialize GitRepository in " + root.getPresentableUrl(), e); @@ -170,6 +169,11 @@ public class GitRepositoryManagerImpl extends AbstractProjectComponent implement } } } + + REPO_LOCK.writeLock().lock(); + try { + myRepositories.clear(); + myRepositories.putAll(repositories); } finally { REPO_LOCK.writeLock().unlock(); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInsight/GroovyMarkerTypes.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInsight/GroovyMarkerTypes.java index 17858dc94695..2ccadd1a866b 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInsight/GroovyMarkerTypes.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInsight/GroovyMarkerTypes.java @@ -333,14 +333,17 @@ public class GroovyMarkerTypes { } @Override - public void run(@NotNull ProgressIndicator indicator) { + public void run(final @NotNull ProgressIndicator indicator) { super.run(indicator); for (PsiMethod method : PsiImplUtil.getMethodOrReflectedMethods(myMethod)) { OverridingMethodsSearch.search(method, true).forEach( new CommonProcessors.CollectProcessor() { @Override public boolean process(PsiMethod psiMethod) { - updateComponent(com.intellij.psi.impl.PsiImplUtil.handleMirror(psiMethod), myRenderer.getComparator()); + if (!updateComponent(com.intellij.psi.impl.PsiImplUtil.handleMirror(psiMethod), myRenderer.getComparator())) { + indicator.cancel(); + } + indicator.checkCanceled(); return true; } }); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/GroovyBlockGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/GroovyBlockGenerator.java index cf293b66cb19..b42bf1cceec7 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/GroovyBlockGenerator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/GroovyBlockGenerator.java @@ -43,6 +43,7 @@ import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes; import org.jetbrains.plugins.groovy.lang.psi.GrQualifiedReference; import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; import org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase; +import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap; import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrThrowsClause; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrLabeledStatement; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement; @@ -312,9 +313,10 @@ public class GroovyBlockGenerator implements GroovyElementTypes { } return blockPsi instanceof GrParameterList && mySettings.ALIGN_MULTILINE_PARAMETERS || - blockPsi instanceof GrExtendsClause && mySettings.ALIGN_MULTILINE_EXTENDS_LIST || - blockPsi instanceof GrThrowsClause && mySettings.ALIGN_MULTILINE_THROWS_LIST || - blockPsi instanceof GrConditionalExpression && mySettings.ALIGN_MULTILINE_TERNARY_OPERATION; + blockPsi instanceof GrExtendsClause && mySettings.ALIGN_MULTILINE_EXTENDS_LIST || + blockPsi instanceof GrThrowsClause && mySettings.ALIGN_MULTILINE_THROWS_LIST || + blockPsi instanceof GrConditionalExpression && mySettings.ALIGN_MULTILINE_TERNARY_OPERATION || + blockPsi instanceof GrListOrMap && myGroovySettings.ALIGN_MULTILINE_LIST_OR_MAP; } private static boolean isListLikeClause(PsiElement blockPsi) { @@ -323,7 +325,8 @@ public class GroovyBlockGenerator implements GroovyElementTypes { blockPsi instanceof GrAssignmentExpression || blockPsi instanceof GrConditionalExpression || blockPsi instanceof GrExtendsClause || - blockPsi instanceof GrThrowsClause; + blockPsi instanceof GrThrowsClause || + blockPsi instanceof GrListOrMap; } private static boolean isKeyword(ASTNode node) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/GroovyCodeStyleSettings.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/GroovyCodeStyleSettings.java index ccdc49a58b69..895f178c762a 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/GroovyCodeStyleSettings.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/GroovyCodeStyleSettings.java @@ -42,6 +42,7 @@ public class GroovyCodeStyleSettings extends CustomCodeStyleSettings { public boolean USE_FLYING_GEESE_BRACES = false; public boolean SPACE_IN_NAMED_ARGUMENT = true; + public boolean ALIGN_MULTILINE_LIST_OR_MAP = false; public GroovyCodeStyleSettings(CodeStyleSettings container) { super("GroovyCodeStyleSettings", container); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/GroovyLanguageCodeStyleSettingsProvider.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/GroovyLanguageCodeStyleSettingsProvider.java index 828e9939cae2..6cd8df934c1a 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/GroovyLanguageCodeStyleSettingsProvider.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/GroovyLanguageCodeStyleSettingsProvider.java @@ -44,6 +44,7 @@ public class GroovyLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSe if (settingsType == SettingsType.WRAPPING_AND_BRACES_SETTINGS) { consumer.showAllStandardOptions(); consumer.showCustomOption(GroovyCodeStyleSettings.class, "USE_FLYING_GEESE_BRACES", "Use flying geese braces", CodeStyleSettingsCustomizable.WRAPPING_BRACES); + consumer.showCustomOption(GroovyCodeStyleSettings.class, "ALIGN_MULTILINE_LIST_OR_MAP", "Align when multiple", "List and map literals"); return; } if (settingsType == SettingsType.SPACING_SETTINGS) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovyIndentProcessor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovyIndentProcessor.java index 3272fd5d8b92..a2d41525e024 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovyIndentProcessor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovyIndentProcessor.java @@ -133,9 +133,14 @@ public abstract class GroovyIndentProcessor implements GroovyElementTypes { // For arguments if (psiParent instanceof GrArgumentList) { - if (child.getElementType() != mLPAREN && - child.getElementType() != mRPAREN) { - return Indent.getContinuationIndent(); + if (child.getElementType() != mLPAREN && child.getElementType() != mRPAREN /*&& child.getElementType() != mCOMMA*/) { + return Indent.getContinuationWithoutFirstIndent(); + } + } + + if (psiParent instanceof GrListOrMap) { + if (child.getElementType() != mLBRACK && child.getElementType() != mRBRACK /*&& child.getElementType() != mCOMMA*/) { + return Indent.getContinuationWithoutFirstIndent(); } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/editor/GroovyQuoteHandler.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/editor/GroovyQuoteHandler.java index 381f82100ac2..aed89f37e90d 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/editor/GroovyQuoteHandler.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/editor/GroovyQuoteHandler.java @@ -17,6 +17,7 @@ package org.jetbrains.plugins.groovy.lang.editor; import com.intellij.codeInsight.editorActions.MultiCharQuoteHandler; +import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.highlighter.HighlighterIterator; import com.intellij.openapi.util.TextRange; @@ -64,7 +65,9 @@ public class GroovyQuoteHandler implements MultiCharQuoteHandler { @Override public CharSequence getClosingQuote(HighlighterIterator iterator, int offset) { if (offset >= 3) { - String quote = iterator.getDocument().getText(new TextRange(offset - 3, offset)); + Document document = iterator.getDocument(); + if (document == null) return null; + String quote = document.getText(new TextRange(offset - 3, offset)); if ("'''".equals(quote)) return quote; if ("\"\"\"".equals(quote)) return quote; } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/StubGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/StubGenerator.java index 322e4c2a55fe..94a07495c812 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/StubGenerator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/StubGenerator.java @@ -380,7 +380,11 @@ public class StubGenerator implements ClassItemGenerator { return eval.toString() + "f"; } else if (eval instanceof Character) { - return "'" + ((Character)eval).charValue() + "'"; + StringBuilder buffer = new StringBuilder(); + buffer.append('\''); + StringUtil.escapeStringCharacters(1, Character.toString(((Character)eval).charValue()), buffer); + buffer.append('\''); + return buffer.toString(); } if (eval instanceof Number || eval instanceof Boolean) { return eval.toString(); diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyDebuggerTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyDebuggerTest.groovy index 7ae39e4605fa..cf6055d4bc69 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyDebuggerTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyDebuggerTest.groovy @@ -241,6 +241,23 @@ new Runnable() { } } + void testEvalInStaticMethod() { + myFixture.addFileToProject('Foo.groovy', '''\ +static def foo() { + int x = 5 + print x +} + +foo() + +''') + addBreakpoint 'Foo.groovy', 2 + runDebugger 'Foo', { + waitForBreakpoint() + eval 'x', '5' + } + } + private def addBreakpoint(String fileName, int line) { VirtualFile file = null edt {