From 51340c94d98d34382d8d47fc421c68a4c24fbfab Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Wed, 24 Nov 2010 19:22:46 +0300 Subject: [PATCH 01/22] don't hide actions in the main menu --- .../impl/actions/FoldingActionGroup.java | 42 ------------------ .../actions/ProjectViewActionGroup.java | 43 ------------------- .../ide/actions/CodeEditorActionGroup.java | 41 ------------------ .../src/idea/LangActions.xml | 6 +-- 4 files changed, 3 insertions(+), 129 deletions(-) delete mode 100644 platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/FoldingActionGroup.java delete mode 100644 platform/lang-impl/src/com/intellij/ide/projectView/actions/ProjectViewActionGroup.java delete mode 100644 platform/platform-impl/src/com/intellij/ide/actions/CodeEditorActionGroup.java diff --git a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/FoldingActionGroup.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/FoldingActionGroup.java deleted file mode 100644 index 1a139fcb1870..000000000000 --- a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/FoldingActionGroup.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2000-2009 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.folding.impl.actions; - -import com.intellij.openapi.actionSystem.*; -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.editor.ex.FoldingModelEx; -import com.intellij.openapi.project.DumbAware; - -public class FoldingActionGroup extends DefaultActionGroup implements DumbAware { - public FoldingActionGroup() { - super(); - } - - public void update(AnActionEvent event){ - Presentation presentation = event.getPresentation(); - DataContext dataContext = event.getDataContext(); - - Editor editor = PlatformDataKeys.EDITOR.getData(dataContext); - if (editor == null){ - presentation.setVisible(false); - return; - } - - FoldingModelEx foldingModel = (FoldingModelEx)editor.getFoldingModel(); - presentation.setVisible(foldingModel.isFoldingEnabled()); - } -} \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/actions/ProjectViewActionGroup.java b/platform/lang-impl/src/com/intellij/ide/projectView/actions/ProjectViewActionGroup.java deleted file mode 100644 index f34fcf03bcbb..000000000000 --- a/platform/lang-impl/src/com/intellij/ide/projectView/actions/ProjectViewActionGroup.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2000-2009 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.ide.projectView.actions; - -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.DefaultActionGroup; -import com.intellij.openapi.actionSystem.PlatformDataKeys; -import com.intellij.openapi.actionSystem.Presentation; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.wm.ToolWindowId; -import com.intellij.openapi.wm.ToolWindowManager; - -public final class ProjectViewActionGroup extends DefaultActionGroup { - public ProjectViewActionGroup() { - super(); - } - - public void update(AnActionEvent event){ - Presentation presentation = event.getPresentation(); - Project project = PlatformDataKeys.PROJECT.getData(event.getDataContext()); - if (project == null) { - presentation.setVisible(false); - return; - } - String id = ToolWindowManager.getInstance(project).getActiveToolWindowId(); - boolean isProjectViewActive = ToolWindowId.PROJECT_VIEW.equals(id); - presentation.setVisible(isProjectViewActive); - } -} \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/ide/actions/CodeEditorActionGroup.java b/platform/platform-impl/src/com/intellij/ide/actions/CodeEditorActionGroup.java deleted file mode 100644 index 43597f77ac24..000000000000 --- a/platform/platform-impl/src/com/intellij/ide/actions/CodeEditorActionGroup.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2000-2009 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.ide.actions; - -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.DefaultActionGroup; -import com.intellij.openapi.actionSystem.PlatformDataKeys; -import com.intellij.openapi.actionSystem.Presentation; -import com.intellij.openapi.project.DumbAware; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.wm.ToolWindowManager; - -public class CodeEditorActionGroup extends DefaultActionGroup implements DumbAware { - public CodeEditorActionGroup() { - super(); - } - - public void update(AnActionEvent event){ - Presentation presentation = event.getPresentation(); - Project project = PlatformDataKeys.PROJECT.getData(event.getDataContext()); - if (project == null) { - presentation.setVisible(false); - return; - } - boolean active = ToolWindowManager.getInstance(project).isEditorComponentActive(); - presentation.setVisible(active); - } -} \ No newline at end of file diff --git a/platform/platform-resources/src/idea/LangActions.xml b/platform/platform-resources/src/idea/LangActions.xml index 9c08ef8d9014..2f5f09ae5270 100644 --- a/platform/platform-resources/src/idea/LangActions.xml +++ b/platform/platform-resources/src/idea/LangActions.xml @@ -134,7 +134,7 @@ - + @@ -146,7 +146,7 @@ - + @@ -156,7 +156,7 @@ - + From 8f83ddb2596deb94bfeb071c66bd456d651bf2c7 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Wed, 24 Nov 2010 19:30:40 +0300 Subject: [PATCH 02/22] ability to work with multiple editor windows --- .../openapi/fileEditor/FileEditorManager.java | 15 +++++ .../com/intellij/ide/actions/Switcher.java | 44 +++++++++++--- .../fileEditor/ex/FileEditorManagerEx.java | 12 +++- .../impl/FileEditorManagerImpl.java | 59 +++++++++++++------ .../impl/IdeDocumentHistoryImpl.java | 2 +- .../testFramework/TestEditorManagerImpl.java | 4 +- 6 files changed, 105 insertions(+), 31 deletions(-) diff --git a/platform/platform-api/src/com/intellij/openapi/fileEditor/FileEditorManager.java b/platform/platform-api/src/com/intellij/openapi/fileEditor/FileEditorManager.java index 0a91e3cff630..dc84b0d8d1dc 100644 --- a/platform/platform-api/src/com/intellij/openapi/fileEditor/FileEditorManager.java +++ b/platform/platform-api/src/com/intellij/openapi/fileEditor/FileEditorManager.java @@ -37,6 +37,21 @@ public abstract class FileEditorManager { */ @NotNull public abstract FileEditor[] openFile(@NotNull VirtualFile file, boolean focusEditor); + + /** + * Opens a file + * + * @param file file to open + * @param focusEditor true if need to focus + * @param useActiveSplitter if false then manager will search + * the file through all splitters + * + * @return array of opened editors + */ + @NotNull public FileEditor[] openFile(@NotNull VirtualFile file, boolean focusEditor, boolean useActiveSplitter) { + throw new UnsupportedOperationException("Not implemented"); + } + /** * Closes all editors opened for the file. * diff --git a/platform/platform-impl/src/com/intellij/ide/actions/Switcher.java b/platform/platform-impl/src/com/intellij/ide/actions/Switcher.java index 4c39bbe0b6f9..d9ed5b2d62a6 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/Switcher.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/Switcher.java @@ -21,8 +21,11 @@ import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.markup.EffectType; import com.intellij.openapi.editor.markup.TextAttributes; +import com.intellij.openapi.fileEditor.FileEditor; import com.intellij.openapi.fileEditor.FileEditorManager; +import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx; import com.intellij.openapi.fileEditor.impl.EditorHistoryManager; +import com.intellij.openapi.fileEditor.impl.EditorWindow; import com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl; import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; @@ -102,11 +105,13 @@ public class Switcher extends AnAction implements DumbAware { public void actionPerformed(AnActionEvent e) { final Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext()); if (project == null) return; + boolean selectFirstItem = false; if (SWITCHER == null) { synchronized (Switcher.class) { if (SWITCHER == null) { SWITCHER = new SwitcherPanel(project); FeatureUsageTracker.getInstance().triggerFeatureUsed(SWITCHER_FEATURE_ID); + selectFirstItem = !FileEditorManagerEx.getInstanceEx(project).hasOpenedFile(); } } } @@ -114,7 +119,11 @@ public class Switcher extends AnAction implements DumbAware { if (e.getInputEvent().isShiftDown()) { SWITCHER.goBack(); } else { - SWITCHER.goForward(); + if (selectFirstItem) { + SWITCHER.files.setSelectedIndex(0); + } else { + SWITCHER.goForward(); + } } } @@ -128,6 +137,7 @@ public class Switcher extends AnAction implements DumbAware { final JLabel pathLabel = new JLabel(" "); final JPanel descriptions; final Project project; + final Map files2editors; SwitcherPanel(Project project) { super(new BorderLayout(0, 0)); @@ -212,11 +222,20 @@ public class Switcher extends AnAction implements DumbAware { separator.setBackground(Color.WHITE); final FileEditorManager editorManager = FileEditorManager.getInstance(project); - final VirtualFile[] openFiles = editorManager.getOpenFiles(); - - try { - Arrays.sort(openFiles, new RecentFilesComparator(project)); - } catch (Exception e) {// IndexNotReadyException + final FileEditor[] allEditors = editorManager.getAllEditors(); + files2editors = new HashMap(); + for (FileEditor editor : allEditors) { + files2editors.put(((FileEditorManagerImpl)editorManager).getFile(editor), editor); + } + final VirtualFile[] recentFiles = EditorHistoryManager.getInstance(project).getFiles(); + final ArrayList openFiles = new ArrayList(); + for (VirtualFile recentFile : recentFiles) { + openFiles.add(0, recentFile); + } + final ArrayList tmp = new ArrayList(files2editors.keySet()); + tmp.removeAll(openFiles); + for (VirtualFile virtualFile : tmp) { + openFiles.add(0, virtualFile); } final DefaultListModel filesModel = new DefaultListModel(); @@ -315,7 +334,15 @@ public class Switcher extends AnAction implements DumbAware { return true; } }).createPopup(); - myPopup.showInCenterOf(ideFrame.getContentPane()); + Component comp = null; + final EditorWindow result = FileEditorManagerEx.getInstanceEx(project).getActiveWindow().getResult(); + if (result != null) { + comp = result.getOwner(); + } + if (comp == null) { + comp = ideFrame.getContentPane(); + } + myPopup.showInCenterOf(comp); } private int getModifiers(ShortcutSet shortcutSet) { @@ -494,7 +521,8 @@ public class Switcher extends AnAction implements DumbAware { ((ToolWindow)value).activate(null, true, true); } else if (value instanceof VirtualFile) { - FileEditorManager.getInstance(project).openFile((VirtualFile)value, true); + final VirtualFile file = (VirtualFile)value; + FileEditorManager.getInstance(project).openFile(file, true, true); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/ex/FileEditorManagerEx.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/ex/FileEditorManagerEx.java index 2db93fc7644b..156c2836d3c1 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/ex/FileEditorManagerEx.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/ex/FileEditorManagerEx.java @@ -123,10 +123,18 @@ public abstract class FileEditorManagerEx extends FileEditorManager { @NotNull public FileEditor[] openFile(@NotNull final VirtualFile file, final boolean focusEditor) { - return openFileWithProviders(file, focusEditor).getFirst (); + return openFileWithProviders(file, focusEditor, false).getFirst (); } - @NotNull public abstract Pair openFileWithProviders(@NotNull VirtualFile file, boolean focusEditor); + @NotNull + @Override + public FileEditor[] openFile(@NotNull VirtualFile file, boolean focusEditor, boolean useActiveSplitter) { + return openFileWithProviders(file, focusEditor, useActiveSplitter).getFirst(); + } + + @NotNull public abstract Pair openFileWithProviders(@NotNull VirtualFile file, + boolean focusEditor, + boolean useActiveSplitter); public abstract boolean isChanged(@NotNull EditorComposite editor); diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileEditorManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileEditorManagerImpl.java index f453068d29ab..d6d351e878c3 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileEditorManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileEditorManagerImpl.java @@ -547,18 +547,34 @@ public class FileEditorManagerImpl extends FileEditorManagerEx implements Projec //-------------------------------------- Open File ---------------------------------------- - @NotNull public Pair openFileWithProviders(@NotNull final VirtualFile file, final boolean focusEditor) { + @NotNull public Pair openFileWithProviders(@NotNull final VirtualFile file, + final boolean focusEditor, + boolean useActiveSplitter) { if (!file.isValid()) { throw new IllegalArgumentException("file is not valid: " + file); } assertDispatchThread(); - EditorsSplitters splitters = getSplitters(); - EditorWindow wndToOpenIn = splitters.getCurrentWindow(); + EditorWindow wndToOpenIn = null; + if (useActiveSplitter) { + for (EditorsSplitters splitters : getAllSplitters()) { + final EditorWindow window = splitters.getCurrentWindow(); + if (window == null) continue; + + if (window.isFileOpen(file)) { + wndToOpenIn = window; + if (wndToOpenIn != getActiveWindow().getResult()) { + System.out.println("Not active"); + } + break; + } + } + } else { + wndToOpenIn = getSplitters().getCurrentWindow(); + } if (wndToOpenIn == null) { - wndToOpenIn = splitters.getOrCreateCurrentWindow(file); + wndToOpenIn = getSplitters().getOrCreateCurrentWindow(file); } - return openFileImpl2(wndToOpenIn, file, focusEditor); } @@ -728,7 +744,7 @@ public class FileEditorManagerImpl extends FileEditorManagerEx implements Projec if (!ApplicationManagerEx.getApplicationEx().isUnitTestMode()) { if (focusEditor) { //myFirstIsActive = myTabbedContainer1.equals(tabbedContainer); - window.setAsCurrentWindow(false); + window.setAsCurrentWindow(true); ToolWindowManager.getInstance(myProject).activateEditorComponent(); } } @@ -1018,10 +1034,13 @@ public class FileEditorManagerImpl extends FileEditorManagerEx implements Projec public FileEditor[] getAllEditors() { assertReadAccess(); final ArrayList result = new ArrayList(); - final EditorWithProviderComposite[] editorsComposites = getSplitters().getEditorsComposites(); - for (EditorWithProviderComposite editorsComposite : editorsComposites) { - final FileEditor[] editors = editorsComposite.getEditors(); - ContainerUtil.addAll(result, editors); + final Set allSplitters = getAllSplitters(); + for (EditorsSplitters splitter : allSplitters) { + final EditorWithProviderComposite[] editorsComposites = splitter.getEditorsComposites(); + for (EditorWithProviderComposite editorsComposite : editorsComposites) { + final FileEditor[] editors = editorsComposite.getEditors(); + ContainerUtil.addAll(result, editors); + } } return result.toArray(new FileEditor[result.size()]); } @@ -1168,15 +1187,17 @@ public class FileEditorManagerImpl extends FileEditorManagerEx implements Projec } private EditorWithProviderComposite getEditorComposite(@NotNull final FileEditor editor) { - final EditorWithProviderComposite[] editorsComposites = getSplitters().getEditorsComposites(); - for (int i = editorsComposites.length - 1; i >= 0; i--) { - final EditorWithProviderComposite composite = editorsComposites[i]; - final FileEditor[] editors = composite.getEditors(); - for (int j = editors.length - 1; j >= 0; j--) { - final FileEditor _editor = editors[j]; - LOG.assertTrue(_editor != null); - if (editor.equals(_editor)) { - return composite; + for (EditorsSplitters splitters : getAllSplitters()) { + final EditorWithProviderComposite[] editorsComposites = splitters.getEditorsComposites(); + for (int i = editorsComposites.length - 1; i >= 0; i--) { + final EditorWithProviderComposite composite = editorsComposites[i]; + final FileEditor[] editors = composite.getEditors(); + for (int j = editors.length - 1; j >= 0; j--) { + final FileEditor _editor = editors[j]; + LOG.assertTrue(_editor != null); + if (editor.equals(_editor)) { + return composite; + } } } } diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/IdeDocumentHistoryImpl.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/IdeDocumentHistoryImpl.java index 52011d1180bf..f4b1eb5a862b 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/IdeDocumentHistoryImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/IdeDocumentHistoryImpl.java @@ -443,7 +443,7 @@ public class IdeDocumentHistoryImpl extends IdeDocumentHistory implements Projec private void gotoPlaceInfo(@NotNull PlaceInfo info) { // TODO: Msk final boolean wasActive = myToolWindowManager.isEditorComponentActive(); - final Pair editorsWithProviders = myEditorManager.openFileWithProviders(info.getFile(), wasActive); + final Pair editorsWithProviders = myEditorManager.openFileWithProviders(info.getFile(), wasActive, false); final FileEditor [] editors = editorsWithProviders.getFirst(); final FileEditorProvider[] providers = editorsWithProviders.getSecond(); for (int i = 0; i < editors.length; i++) { diff --git a/platform/testFramework/src/com/intellij/testFramework/TestEditorManagerImpl.java b/platform/testFramework/src/com/intellij/testFramework/TestEditorManagerImpl.java index 1ca79f76ec81..b63fe23b8477 100644 --- a/platform/testFramework/src/com/intellij/testFramework/TestEditorManagerImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/TestEditorManagerImpl.java @@ -66,7 +66,9 @@ import java.util.Map; @Override @NotNull - public Pair openFileWithProviders(@NotNull VirtualFile file, boolean focusEditor) { + public Pair openFileWithProviders(@NotNull VirtualFile file, + boolean focusEditor, + boolean useActiveSplitter) { Editor editor = openTextEditor(new OpenFileDescriptor(myProject, file), focusEditor); final FileEditor fileEditor = TextEditorProvider.getInstance().getTextEditor(editor); return Pair.create (new FileEditor[] {fileEditor}, new FileEditorProvider[] {getProvider (fileEditor)}); From 8b3532743653f370a595a2af0a1956fb4465d4e7 Mon Sep 17 00:00:00 2001 From: Oleg Shpynov Date: Wed, 24 Nov 2010 19:38:31 +0300 Subject: [PATCH 03/22] RUBY-7236 refactor rename dialog: "Refactor" and "Preview" buttons should do different things --- .../src/com/intellij/refactoring/rename/RenameDialog.java | 5 +++++ .../refactoring/rename/RenamePsiElementProcessor.java | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/RenameDialog.java b/platform/lang-impl/src/com/intellij/refactoring/rename/RenameDialog.java index 561beab8581f..c03611f3fc18 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/rename/RenameDialog.java +++ b/platform/lang-impl/src/com/intellij/refactoring/rename/RenameDialog.java @@ -91,6 +91,11 @@ public class RenameDialog extends RefactoringDialog { myHelpID = RenamePsiElementProcessor.forElement(psiElement).getHelpID(psiElement); } + @Override + protected boolean hasPreviewButton() { + return RenamePsiElementProcessor.forElement(myPsiElement).showRenamePreviewButton(myPsiElement); + } + protected void dispose() { myNameSuggestionsField.removeDataChangedListener(myNameChangedListener); super.dispose(); diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/RenamePsiElementProcessor.java b/platform/lang-impl/src/com/intellij/refactoring/rename/RenamePsiElementProcessor.java index 3de38efaca85..dde8aeda8421 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/rename/RenamePsiElementProcessor.java +++ b/platform/lang-impl/src/com/intellij/refactoring/rename/RenamePsiElementProcessor.java @@ -139,6 +139,10 @@ public abstract class RenamePsiElementProcessor { } } + public boolean showRenamePreviewButton(final PsiElement psiElement){ + return true; + } + /** * Returns the element to be renamed instead of the element on which the rename refactoring was invoked (for example, a super method * of an inherited method). From 3e850e27d73e56fbdfcca711fe16e23afe3e2c54 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Wed, 24 Nov 2010 18:53:59 +0300 Subject: [PATCH 04/22] do not perform cleanup if there is some space to grow --- .../intellij/openapi/util/LowMemoryWatcher.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/platform/util/src/com/intellij/openapi/util/LowMemoryWatcher.java b/platform/util/src/com/intellij/openapi/util/LowMemoryWatcher.java index 1739d9ac1881..daeaeb1e6027 100644 --- a/platform/util/src/com/intellij/openapi/util/LowMemoryWatcher.java +++ b/platform/util/src/com/intellij/openapi/util/LowMemoryWatcher.java @@ -31,6 +31,7 @@ import java.util.concurrent.CopyOnWriteArrayList; * Date: Aug 24, 2010 */ public class LowMemoryWatcher { + private static final long MEM_THRESHOLD = 5 /*MB*/ * 1024 * 1024; public static abstract class ForceableAdapter implements Forceable { public boolean isDirty() { @@ -58,17 +59,22 @@ public class LowMemoryWatcher { ourRefQueue.remove(); updateRef(); + final Runtime runtime = Runtime.getRuntime(); + final boolean shouldCleanup = (runtime.maxMemory() - runtime.totalMemory()) <= MEM_THRESHOLD; + for (WeakReference instanceRef : ourInstances) { final LowMemoryWatcher watcher = instanceRef.get(); if (watcher == null) { toRemove.add(instanceRef); } else { - try { - watcher.doCleanup(); - } - catch (Throwable e) { - LOG.info(e); + if (shouldCleanup) { + try { + watcher.doCleanup(); + } + catch (Throwable e) { + LOG.info(e); + } } } } From 244e0fd45cc5faca0c25f76d08adeb4490060d23 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Wed, 24 Nov 2010 18:56:55 +0300 Subject: [PATCH 05/22] do not perform cleanup if there is some space to grow, part 2 --- .../com/intellij/openapi/util/LowMemoryWatcher.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/platform/util/src/com/intellij/openapi/util/LowMemoryWatcher.java b/platform/util/src/com/intellij/openapi/util/LowMemoryWatcher.java index daeaeb1e6027..75a12e9a590c 100644 --- a/platform/util/src/com/intellij/openapi/util/LowMemoryWatcher.java +++ b/platform/util/src/com/intellij/openapi/util/LowMemoryWatcher.java @@ -50,6 +50,7 @@ public class LowMemoryWatcher { static { final Thread thread = new Thread("LowMemoryWatcher") { + boolean shouldCleanup = false; public void run() { updateRef(); final Set> toRemove = new HashSet>(); @@ -58,10 +59,12 @@ public class LowMemoryWatcher { try { ourRefQueue.remove(); updateRef(); - - final Runtime runtime = Runtime.getRuntime(); - final boolean shouldCleanup = (runtime.maxMemory() - runtime.totalMemory()) <= MEM_THRESHOLD; - + + if (!shouldCleanup) { + final Runtime runtime = Runtime.getRuntime(); + shouldCleanup = (runtime.maxMemory() - runtime.totalMemory()) <= MEM_THRESHOLD; + } + for (WeakReference instanceRef : ourInstances) { final LowMemoryWatcher watcher = instanceRef.get(); if (watcher == null) { From 97dc0c7efdead5ec5d44339ae31e810264bbba60 Mon Sep 17 00:00:00 2001 From: Gregory Shrago Date: Wed, 24 Nov 2010 17:27:13 +0300 Subject: [PATCH 06/22] EA-23830 - IAE: RangeMarkerImpl. --- .../execution/console/LanguageConsoleImpl.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java index 4b9a4b34f958..4d4022719caa 100644 --- a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java @@ -369,12 +369,17 @@ public class LanguageConsoleImpl implements Disposable, TypeSafeDataProvider { //offset can be changed after text trimming after insert due to buffer constraints appendToHistoryDocument(history, text); int offset = history.getTextLength() - text.length(); - final HighlighterIterator iterator = consoleEditor.getHighlighter().createIterator(0); + final int localOffset = textRange.getStartOffset(); + final HighlighterIterator iterator = consoleEditor.getHighlighter().createIterator(localOffset); + final int localEndOffset = textRange.getEndOffset(); while (!iterator.atEnd()) { - final int localOffset = textRange.getStartOffset(); - final int start = Math.max(iterator.getStart(), localOffset) - localOffset; - final int end = Math.min(iterator.getEnd(), textRange.getEndOffset()) - localOffset; - markupModel.addRangeHighlighter(start + offset, end + offset, HighlighterLayer.SYNTAX, iterator.getTextAttributes(), + final int itStart = iterator.getStart(); + if (itStart > localEndOffset) break; + final int itEnd = iterator.getEnd(); + if (itEnd < localOffset) continue; + final int start = Math.max(itStart, localOffset) - localOffset + offset; + final int end = Math.min(itEnd, localEndOffset) - localOffset + offset; + markupModel.addRangeHighlighter(start, end, HighlighterLayer.SYNTAX, iterator.getTextAttributes(), HighlighterTargetArea.EXACT_RANGE); iterator.advance(); From 7194dd37c1cc8ce1d1e571e5b196e80ac98f9455 Mon Sep 17 00:00:00 2001 From: Gregory Shrago Date: Wed, 24 Nov 2010 18:26:46 +0300 Subject: [PATCH 07/22] EA-23830 - IAE: RangeMarkerImpl. --- .../execution/console/LanguageConsoleImpl.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java index 4d4022719caa..bc2768702e63 100644 --- a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java @@ -369,19 +369,19 @@ public class LanguageConsoleImpl implements Disposable, TypeSafeDataProvider { //offset can be changed after text trimming after insert due to buffer constraints appendToHistoryDocument(history, text); int offset = history.getTextLength() - text.length(); - final int localOffset = textRange.getStartOffset(); - final HighlighterIterator iterator = consoleEditor.getHighlighter().createIterator(localOffset); + final int localStartOffset = textRange.getStartOffset(); + final HighlighterIterator iterator = consoleEditor.getHighlighter().createIterator(localStartOffset); final int localEndOffset = textRange.getEndOffset(); while (!iterator.atEnd()) { final int itStart = iterator.getStart(); if (itStart > localEndOffset) break; final int itEnd = iterator.getEnd(); - if (itEnd < localOffset) continue; - final int start = Math.max(itStart, localOffset) - localOffset + offset; - final int end = Math.min(itEnd, localEndOffset) - localOffset + offset; - markupModel.addRangeHighlighter(start, end, HighlighterLayer.SYNTAX, iterator.getTextAttributes(), - HighlighterTargetArea.EXACT_RANGE); - + if (itEnd >= localStartOffset) { + final int start = Math.max(itStart, localStartOffset) - localStartOffset + offset; + final int end = Math.min(itEnd, localEndOffset) - localStartOffset + offset; + markupModel.addRangeHighlighter(start, end, HighlighterLayer.SYNTAX, iterator.getTextAttributes(), + HighlighterTargetArea.EXACT_RANGE); + } iterator.advance(); } if (myDoSaveErrorsToHistory) { From 557b4825b1bb0618341e746438132cc798a9e163 Mon Sep 17 00:00:00 2001 From: Gregory Shrago Date: Wed, 24 Nov 2010 19:54:05 +0300 Subject: [PATCH 08/22] sql completion test fix & non-strict TextRange.containsOffset (same semantics for findReferenceAt & reference completion) --- platform/lang-api/src/com/intellij/psi/ReferenceRange.java | 4 ++-- .../src/com/intellij/psi/impl/SharedPsiElementImplUtil.java | 2 +- platform/util/src/com/intellij/openapi/util/TextRange.java | 4 ++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/platform/lang-api/src/com/intellij/psi/ReferenceRange.java b/platform/lang-api/src/com/intellij/psi/ReferenceRange.java index f079c906fdfd..2ac202ecb1ae 100644 --- a/platform/lang-api/src/com/intellij/psi/ReferenceRange.java +++ b/platform/lang-api/src/com/intellij/psi/ReferenceRange.java @@ -59,12 +59,12 @@ public class ReferenceRange { public static boolean containsOffsetInElement(PsiReference ref, int offset) { if (ref instanceof MultiRangeReference) { for (TextRange range : ((MultiRangeReference)ref).getRanges()) { - if (range.contains(offset)) return true; + if (range.containsOffset(offset)) return true; } return false; } - return ref.getRangeInElement().contains(offset); + return ref.getRangeInElement().containsOffset(offset); } public static boolean containsRangeInElement(PsiReference ref, TextRange rangeInElement) { diff --git a/platform/lang-impl/src/com/intellij/psi/impl/SharedPsiElementImplUtil.java b/platform/lang-impl/src/com/intellij/psi/impl/SharedPsiElementImplUtil.java index a99d6c01788c..59754f994cb8 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/SharedPsiElementImplUtil.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/SharedPsiElementImplUtil.java @@ -68,7 +68,7 @@ public class SharedPsiElementImplUtil { LOG.error(element); } for (TextRange range : ReferenceRange.getRanges(reference)) { - if (range.getStartOffset() <= offset && offset <= range.getEndOffset()) { + if (range.containsOffset(offset)) { outReferences.add(reference); } } diff --git a/platform/util/src/com/intellij/openapi/util/TextRange.java b/platform/util/src/com/intellij/openapi/util/TextRange.java index 83af33e86d94..e0d555ba26af 100644 --- a/platform/util/src/com/intellij/openapi/util/TextRange.java +++ b/platform/util/src/com/intellij/openapi/util/TextRange.java @@ -57,6 +57,10 @@ public class TextRange { return myStartOffset <= startOffset && myEndOffset >= endOffset; } + public boolean containsOffset(int offset) { + return myStartOffset <= offset && offset <= myEndOffset; + } + public String toString() { return "(" + myStartOffset + "," + myEndOffset + ")"; } From 59811afa49fee119778e3da631c4b7a9508ebd32 Mon Sep 17 00:00:00 2001 From: "peter.gromov" Date: Wed, 24 Nov 2010 18:21:11 +0300 Subject: [PATCH 09/22] diagnostics --- .../xml/impl/PhysicalDomParentStrategy.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/xml/dom-impl/src/com/intellij/util/xml/impl/PhysicalDomParentStrategy.java b/xml/dom-impl/src/com/intellij/util/xml/impl/PhysicalDomParentStrategy.java index 546ed073f57c..fd8cdbda9b52 100644 --- a/xml/dom-impl/src/com/intellij/util/xml/impl/PhysicalDomParentStrategy.java +++ b/xml/dom-impl/src/com/intellij/util/xml/impl/PhysicalDomParentStrategy.java @@ -15,6 +15,7 @@ */ package com.intellij.util.xml.impl; +import com.intellij.openapi.application.ex.ApplicationManagerEx; import com.intellij.psi.PsiElement; import com.intellij.psi.xml.XmlElement; import com.intellij.psi.xml.XmlEntityRef; @@ -82,10 +83,28 @@ public class PhysicalDomParentStrategy implements DomParentStrategy { final XmlElement thatElement = ((PhysicalDomParentStrategy)o).myElement; if (xmlElementsEqual(myElement, thatElement)) { if (myElement != thatElement) { + //todo remove this assertion before X release + if (ApplicationManagerEx.getApplicationEx().isInternal()) { + PsiElement cur = myElement; + while (cur != null && !cur.isPhysical()) { + cur = cur.getParent(); + } + throw new AssertionError(myElement.getText() + "; including=" + (cur == null ? null : cur.getText())); + } + final PsiElement nav1 = myElement.getNavigationElement(); final PsiElement nav2 = thatElement.getNavigationElement(); - assert nav1 == nav2 : nav1.getContainingFile() + ":" + nav1.getTextRange().getStartOffset() + "!=" + nav2.getContainingFile() + ":" + nav2.getTextRange().getStartOffset() + - "; " + (nav1==myElement) + ";" + (nav2==thatElement); + assert nav1 == nav2 : nav1.getContainingFile() + + ":" + + nav1.getTextRange().getStartOffset() + + "!=" + + nav2.getContainingFile() + + ":" + + nav2.getTextRange().getStartOffset() + + "; " + + (nav1 == myElement) + + ";" + + (nav2 == thatElement); } return true; } From 204a0139f4f7720620c676cd3041906b9f4a3c0a Mon Sep 17 00:00:00 2001 From: "peter.gromov" Date: Wed, 24 Nov 2010 18:32:55 +0300 Subject: [PATCH 10/22] stub-based psiAnchor should remember the element type --- .../lang-impl/src/com/intellij/psi/PsiAnchor.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/psi/PsiAnchor.java b/platform/lang-impl/src/com/intellij/psi/PsiAnchor.java index 495501a1e9b2..19e00da24583 100644 --- a/platform/lang-impl/src/com/intellij/psi/PsiAnchor.java +++ b/platform/lang-impl/src/com/intellij/psi/PsiAnchor.java @@ -27,6 +27,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.impl.light.LightElement; import com.intellij.psi.impl.source.PsiFileImpl; import com.intellij.psi.impl.source.PsiFileWithStubSupport; +import com.intellij.psi.stubs.IStubElementType; import com.intellij.psi.stubs.StubBase; import com.intellij.psi.stubs.StubElement; import com.intellij.psi.stubs.StubTree; @@ -65,7 +66,7 @@ public abstract class PsiAnchor { final StubBasedPsiElement elt = (StubBasedPsiElement)element; if (elt.getStub() != null || elt.getElementType().shouldCreateStub(element.getNode())) { int index = calcStubIndex((StubBasedPsiElement)element); - if (index != -1) return new StubIndexReference(file, index); + if (index != -1) return new StubIndexReference(file, index, elt.getElementType()); } } @@ -220,8 +221,10 @@ public abstract class PsiAnchor { private final VirtualFile myVirtualFile; private final Project myProject; private final int myIndex; + private final IStubElementType myElementType; - public StubIndexReference(@NotNull PsiFile file, final int index) { + public StubIndexReference(@NotNull PsiFile file, final int index, IStubElementType elementType) { + myElementType = elementType; myVirtualFile = file.getVirtualFile(); myProject = file.getProject(); myIndex = index; @@ -253,6 +256,8 @@ public abstract class PsiAnchor { if (myIndex >= list.size()) return null; StubElement stub = list.get(myIndex); + if (stub.getStubType() != myElementType) return null; + if (foreign) { final PsiElement cachedPsi = ((StubBase)stub).getCachedPsi(); if (cachedPsi != null) return cachedPsi; @@ -274,12 +279,12 @@ public abstract class PsiAnchor { final StubIndexReference that = (StubIndexReference)o; - return myIndex == that.myIndex && myVirtualFile.equals(that.myVirtualFile); + return myIndex == that.myIndex && myVirtualFile.equals(that.myVirtualFile) && myElementType.equals(that.myElementType); } @Override public int hashCode() { - return 31 * myVirtualFile.hashCode() + myIndex; + return (31 * myVirtualFile.hashCode() + myIndex) * 31 + myElementType.hashCode(); } public int getStartOffset() { From e7b967e28c29cdce974fb10fa7ff7ceb221f15ac Mon Sep 17 00:00:00 2001 From: "peter.gromov" Date: Wed, 24 Nov 2010 18:41:49 +0300 Subject: [PATCH 11/22] don't fail-fast in dom equality check if XML has become invalid (EA-23839) --- .../com/intellij/util/xml/impl/PhysicalDomParentStrategy.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xml/dom-impl/src/com/intellij/util/xml/impl/PhysicalDomParentStrategy.java b/xml/dom-impl/src/com/intellij/util/xml/impl/PhysicalDomParentStrategy.java index fd8cdbda9b52..efed641ff164 100644 --- a/xml/dom-impl/src/com/intellij/util/xml/impl/PhysicalDomParentStrategy.java +++ b/xml/dom-impl/src/com/intellij/util/xml/impl/PhysicalDomParentStrategy.java @@ -114,7 +114,7 @@ public class PhysicalDomParentStrategy implements DomParentStrategy { private static boolean xmlElementsEqual(@NotNull final PsiElement fst, @NotNull final PsiElement snd) { if (fst.equals(snd)) return true; - if (fst.isPhysical() || snd.isPhysical()) return false; + if (fst.isValid() && fst.isPhysical() || snd.isValid() && snd.isPhysical()) return false; if (fst.getTextLength() != snd.getTextLength()) return false; if (fst.getStartOffsetInParent() != snd.getStartOffsetInParent()) return false; From a2983949908042700cdb3894b970a562526040c4 Mon Sep 17 00:00:00 2001 From: "peter.gromov" Date: Wed, 24 Nov 2010 18:43:22 +0300 Subject: [PATCH 12/22] diagnostics for EA-23763 --- .../src/com/intellij/codeInsight/lookup/impl/LookupImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 7c5a9fdf31fc..665a854cf872 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 @@ -476,7 +476,7 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable { JComponent internalComponent = myEditor.getContentComponent(); final JRootPane rootPane = editorComponent.getRootPane(); if (rootPane == null) { - LOG.error(myArranger); + LOG.error(myArranger + "; " + myEditor.isDisposed()); } JLayeredPane layeredPane = rootPane.getLayeredPane(); Point layeredPanePoint=SwingUtilities.convertPoint(internalComponent,location, layeredPane); From 53587741ef728d239adfe6431ca18179dc3a43a8 Mon Sep 17 00:00:00 2001 From: "peter.gromov" Date: Wed, 24 Nov 2010 18:45:11 +0300 Subject: [PATCH 13/22] non-validity in Groovy insert handler (EA-23908) --- .../groovy/lang/completion/GroovyClassNameInsertHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyClassNameInsertHandler.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyClassNameInsertHandler.java index bb6665a7753b..18a6b01dd057 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyClassNameInsertHandler.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyClassNameInsertHandler.java @@ -71,7 +71,7 @@ public class GroovyClassNameInsertHandler implements InsertHandler Date: Wed, 24 Nov 2010 18:45:32 +0300 Subject: [PATCH 14/22] diagnostics expanded for EA-23761 --- .../codeInsight/completion/CompletionProgressIndicator.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java index 1098fcf0f15a..e4059af20b04 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java @@ -391,10 +391,14 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement } myLookup.show(); + //todo remove these assertions before X release + if (!ApplicationManager.getApplication().isUnitTestMode()) { + LOG.assertTrue(myLookup.isVisible()); + } } myLookup.refreshUi(); if (!ApplicationManager.getApplication().isUnitTestMode()) { - LOG.assertTrue(myLookup.isVisible()); + LOG.assertTrue(myLookup.isVisible(), "really?"); } hideAutopopupIfMeaningless(); } From 8a5f2aab44857192ab162c265e551ff3142402ad Mon Sep 17 00:00:00 2001 From: "peter.gromov" Date: Wed, 24 Nov 2010 18:57:10 +0300 Subject: [PATCH 15/22] diagnostics expanded for EA-23759 --- .../codeInsight/completion/CodeCompletionHandlerBase.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 952d526dfe78..924ed2bd50d0 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java @@ -402,7 +402,9 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler { LOG.assertTrue(fileCopy.findElementAt(offset) == insertedElement, "wrong offset"); final TextRange range = insertedElement.getTextRange(); - LOG.assertTrue(range.substring(fileCopy.getText()).equals(insertedElement.getText()), "wrong text"); + if (!range.substring(fileCopy.getText()).equals(insertedElement.getText())) { + LOG.error("wrong text: copy='" + fileCopy.getText() + "'; element='" + insertedElement.getText() + "'"); + } return new CompletionParameters(insertedElement, fileCopy.getOriginalFile(), myCompletionType, offset, invocationCount); } From 68e7693660cab8c608740d73569b61207058c24a Mon Sep 17 00:00:00 2001 From: "peter.gromov" Date: Wed, 24 Nov 2010 18:57:49 +0300 Subject: [PATCH 16/22] more diagnostics for EA-23760 --- .../codeInsight/completion/CompletionProgressIndicator.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java index e4059af20b04..de32ec8550c1 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java @@ -273,7 +273,8 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement private boolean isOutdated() { if (!myDisposed) { - LOG.assertTrue(this == CompletionServiceImpl.getCompletionService().getCurrentCompletion()); + CompletionProgressIndicator current = CompletionServiceImpl.getCompletionService().getCurrentCompletion(); + LOG.assertTrue(this == current, current); } return myDisposed || myEditor.isDisposed() || getProject().isDisposed(); } From fd525fd550039c0380e006714ed9d7ac2badd39b Mon Sep 17 00:00:00 2001 From: "peter.gromov" Date: Wed, 24 Nov 2010 19:01:35 +0300 Subject: [PATCH 17/22] diagnostics for EA-23724 --- .../util/xml/highlighting/DomElementProblemDescriptorImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xml/dom-impl/src/com/intellij/util/xml/highlighting/DomElementProblemDescriptorImpl.java b/xml/dom-impl/src/com/intellij/util/xml/highlighting/DomElementProblemDescriptorImpl.java index 0d4c0385cc88..7e6fd84aeefe 100644 --- a/xml/dom-impl/src/com/intellij/util/xml/highlighting/DomElementProblemDescriptorImpl.java +++ b/xml/dom-impl/src/com/intellij/util/xml/highlighting/DomElementProblemDescriptorImpl.java @@ -169,7 +169,7 @@ public class DomElementProblemDescriptorImpl implements DomElementProblemDescrip private static Pair createTagNameRange(final XmlTag tag) { final PsiElement startToken = XmlTagUtil.getStartTagNameElement(tag); - assert startToken != null; + assert startToken != null : tag.getText(); return Pair.create(startToken.getTextRange().shiftRight(-tag.getTextRange().getStartOffset()), (PsiElement)tag); } From 18903081137eb9c6e32952eaf4ad4242416f983a Mon Sep 17 00:00:00 2001 From: "peter.gromov" Date: Wed, 24 Nov 2010 19:03:58 +0300 Subject: [PATCH 18/22] diagnostics for EA-23685 --- .../plugins/groovy/lang/completion/GroovyCompletionUtil.java | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionUtil.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionUtil.java index aa207ec2f851..3c858adac20c 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionUtil.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionUtil.java @@ -259,6 +259,7 @@ public class GroovyCompletionUtil { } public static LookupElement createClassLookupItem(PsiClass psiClass) { + assert psiClass.isValid(); return AllClassesGetter.createLookupItem(psiClass, new GroovyClassNameInsertHandler()); } From bbe3945d918b1f754edde5d71b9171c4ed819ea3 Mon Sep 17 00:00:00 2001 From: "peter.gromov" Date: Wed, 24 Nov 2010 19:07:43 +0300 Subject: [PATCH 19/22] anchor hasn't survived during the long insertHandler activity (EA-23659) --- .../intellij/codeInsight/completion/DefaultInsertHandler.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/DefaultInsertHandler.java b/java/java-impl/src/com/intellij/codeInsight/completion/DefaultInsertHandler.java index 1c8c9c4f8613..f36da9923d22 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/DefaultInsertHandler.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/DefaultInsertHandler.java @@ -65,6 +65,7 @@ public class DefaultInsertHandler extends TemplateInsertHandler implements Clone final boolean needLeftParenth = isToInsertParenth(context, item); final boolean hasParams = needLeftParenth && hasParams(context, item); + final boolean annotation = insertingAnnotation(context, item); if (CompletionUtil.isOverwrite(item, completionChar)) { removeEndOfIdentifier(needLeftParenth && hasParams, context); @@ -114,7 +115,7 @@ public class DefaultInsertHandler extends TemplateInsertHandler implements Clone }); } - if (insertingAnnotation(context, item)) { + if (annotation) { // Check if someone inserts annotation class that require @ PsiElement elementAt = file.findElementAt(context.getStartOffset()); final PsiElement parentElement = elementAt != null ? elementAt.getParent():null; From 2bebb0acbbf86446ab4b4cbbf30f133ce04ae315 Mon Sep 17 00:00:00 2001 From: "peter.gromov" Date: Wed, 24 Nov 2010 19:28:59 +0300 Subject: [PATCH 20/22] diagnose no selection in lookups (EA-23587) --- .../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 665a854cf872..f9761622f173 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 @@ -712,6 +712,9 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable { public Rectangle getCurrentItemBounds(){ int index = myList.getSelectedIndex(); + if (index < 0) { + LOG.error("No selected element, size=" + myList.getModel().getSize() + "; items" + getItems()); + } Rectangle itmBounds = myList.getCellBounds(index, index); if (itmBounds == null){ LOG.error("No bounds for " + index + "; size=" + myList.getModel().getSize()); From 70f639c5e08b2ed09ec61564525f288a8e62d9cc Mon Sep 17 00:00:00 2001 From: "peter.gromov" Date: Wed, 24 Nov 2010 19:39:37 +0300 Subject: [PATCH 21/22] catch INRE (EA-14960) --- .../JUnitConfigurationModel.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/plugins/junit/src/com/intellij/execution/junit2/configuration/JUnitConfigurationModel.java b/plugins/junit/src/com/intellij/execution/junit2/configuration/JUnitConfigurationModel.java index 0be0a372a0f1..ed59e4822982 100644 --- a/plugins/junit/src/com/intellij/execution/junit2/configuration/JUnitConfigurationModel.java +++ b/plugins/junit/src/com/intellij/execution/junit2/configuration/JUnitConfigurationModel.java @@ -20,6 +20,8 @@ import com.intellij.execution.JavaExecutionUtil; import com.intellij.execution.junit.JUnitConfiguration; import com.intellij.execution.junit.JUnitUtil; import com.intellij.openapi.module.Module; +import com.intellij.openapi.progress.ProcessCanceledException; +import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiClass; @@ -84,12 +86,20 @@ public class JUnitConfigurationModel { final String className = getJUnitTextValue(CLASS); data.TEST_OBJECT = testObject; if (testObject != JUnitConfiguration.TEST_PACKAGE && testObject != JUnitConfiguration.TEST_PATTERN) { - final PsiClass testClass = JUnitUtil.findPsiClass(className, module, myProject); - data.METHOD_NAME = getJUnitTextValue(METHOD); - if (testClass != null && testClass.isValid()) { - data.setMainClass(testClass); + try { + data.METHOD_NAME = getJUnitTextValue(METHOD); + final PsiClass testClass = JUnitUtil.findPsiClass(className, module, myProject); + if (testClass != null && testClass.isValid()) { + data.setMainClass(testClass); + } + else { + data.MAIN_CLASS_NAME = className; + } } - else { + catch (ProcessCanceledException e) { + data.MAIN_CLASS_NAME = className; + } + catch (IndexNotReadyException e) { data.MAIN_CLASS_NAME = className; } } From 5062dead692621c39e804295a5655a01e908ec20 Mon Sep 17 00:00:00 2001 From: "peter.gromov" Date: Wed, 24 Nov 2010 20:05:29 +0300 Subject: [PATCH 22/22] IDEA-61785 Groovy: @GrabResolver annotation is not processed --- .../plugins/groovy/grape/GrabDependencies.java | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/grape/GrabDependencies.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/grape/GrabDependencies.java index 69ab68c70340..f8705143bfc1 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/grape/GrabDependencies.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/grape/GrabDependencies.java @@ -131,16 +131,7 @@ public class GrabDependencies implements IntentionAction { return grAnnotation.getText(); } }; - String common = StringUtil.join(excludes, mapper, ","); - if (!resolvers.isEmpty()) { - if (!common.isEmpty()) { - common += ","; - } - common += StringUtil.join(resolvers, mapper, ","); - } - if (!common.isEmpty()) { - common = "," + common; - } + String common = StringUtil.join(excludes, mapper, " ") + " " + StringUtil.join(resolvers, mapper, " "); final Sdk sdk = ModuleRootManager.getInstance(module).getSdk(); assert sdk != null; @@ -151,7 +142,7 @@ public class GrabDependencies implements IntentionAction { final Map lines = new HashMap(); for (GrAnnotation grab : grabs) { String grabText = grab.getText(); - String query = "@Grapes([" + grabText + common + "])"; + String query = grabText + " " + common; final JavaParameters javaParameters = GroovyScriptRunConfiguration.createJavaParametersWithSdk(module); //debug