diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/tree/render/ToStringRenderer.java b/java/debugger/impl/src/com/intellij/debugger/ui/tree/render/ToStringRenderer.java index 363e7ef64adb..75830bc64d23 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/tree/render/ToStringRenderer.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/tree/render/ToStringRenderer.java @@ -15,9 +15,8 @@ */ package com.intellij.debugger.ui.tree.render; -import com.intellij.ui.classFilter.ClassFilter; -import com.intellij.debugger.DebuggerContext; import com.intellij.debugger.DebuggerBundle; +import com.intellij.debugger.DebuggerContext; import com.intellij.debugger.engine.DebugProcessImpl; import com.intellij.debugger.engine.evaluation.EvaluateException; import com.intellij.debugger.engine.evaluation.EvaluationContext; @@ -29,6 +28,7 @@ import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.JDOMExternalizerUtil; import com.intellij.openapi.util.WriteExternalException; import com.intellij.psi.PsiExpression; +import com.intellij.ui.classFilter.ClassFilter; import com.intellij.xdebugger.impl.ui.XDebuggerUIConstants; import com.sun.jdi.*; import org.jdom.Element; @@ -73,7 +73,7 @@ public class ToStringRenderer extends NodeRendererImpl { final Value value = valueDescriptor.getValue(); BatchEvaluator.getBatchEvaluator(evaluationContext.getDebugProcess()).invoke(new ToStringCommand(evaluationContext, value) { public void evaluationResult(String message) { - valueDescriptor.setValueLabel(message != null ? "\"" + message + "\"" : ""); + valueDescriptor.setValueLabel(message != null ? "\"" + DebuggerUtilsEx.truncateString(message) + "\"" : ""); labelListener.labelChanged(); } diff --git a/java/idea-ui/src/com/intellij/ide/palette/impl/PaletteManager.java b/java/idea-ui/src/com/intellij/ide/palette/impl/PaletteManager.java index afdc835518e1..b6f2063a7043 100644 --- a/java/idea-ui/src/com/intellij/ide/palette/impl/PaletteManager.java +++ b/java/idea-ui/src/com/intellij/ide/palette/impl/PaletteManager.java @@ -19,6 +19,7 @@ package com.intellij.ide.palette.impl; import com.intellij.ide.IdeBundle; import com.intellij.ide.palette.PaletteDragEventListener; import com.intellij.ide.palette.PaletteItem; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.ProjectComponent; import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.fileEditor.FileEditorManagerEvent; @@ -60,20 +61,22 @@ public class PaletteManager implements ProjectComponent { } public void projectOpened() { - StartupManager.getInstance(myProject).registerPostStartupActivity(new Runnable() { - public void run() { - myPaletteWindow = new PaletteWindow(myProject); - myPaletteToolWindow = ToolWindowManager.getInstance(myProject).registerToolWindow(IdeBundle.message("toolwindow.palette"), - myPaletteWindow, - ToolWindowAnchor.RIGHT, - myProject, - true); - myPaletteToolWindow.setIcon(IconLoader.getIcon("/general/toolWindowPalette.png")); - myPaletteToolWindow.setAvailable(false, null); - final MyFileEditorManagerListener myListener = new MyFileEditorManagerListener(); - myFileEditorManager.addFileEditorManagerListener(myListener, myProject); - } - }); + if (!ApplicationManager.getApplication().isHeadlessEnvironment()) { + StartupManager.getInstance(myProject).registerPostStartupActivity(new Runnable() { + public void run() { + myPaletteWindow = new PaletteWindow(myProject); + myPaletteToolWindow = ToolWindowManager.getInstance(myProject).registerToolWindow(IdeBundle.message("toolwindow.palette"), + myPaletteWindow, + ToolWindowAnchor.RIGHT, + myProject, + true); + myPaletteToolWindow.setIcon(IconLoader.getIcon("/general/toolWindowPalette.png")); + myPaletteToolWindow.setAvailable(false, null); + final MyFileEditorManagerListener myListener = new MyFileEditorManagerListener(); + myFileEditorManager.addFileEditorManagerListener(myListener, myProject); + } + }); + } } public void projectClosed() { diff --git a/java/java-impl/java-impl.iml b/java/java-impl/java-impl.iml index c52f97bf075d..f5bd5cce2b5f 100644 --- a/java/java-impl/java-impl.iml +++ b/java/java-impl/java-impl.iml @@ -4,6 +4,7 @@ + diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateMethodQuickFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateMethodQuickFix.java index b232cb7dce86..2826cec4c910 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateMethodQuickFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateMethodQuickFix.java @@ -24,7 +24,6 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Pair; import com.intellij.psi.*; import com.intellij.psi.codeStyle.JavaCodeStyleManager; -import com.intellij.psi.impl.JavaPsiFacadeEx; import com.intellij.psi.util.PsiFormatUtil; import com.intellij.util.Function; import com.intellij.util.IncorrectOperationException; @@ -61,23 +60,18 @@ public class CreateMethodQuickFix implements LocalQuickFix { } public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) { - try { - if (!CodeInsightUtilBase.preparePsiElementForWrite(myTargetClass.getContainingFile())) return; + if (!CodeInsightUtilBase.preparePsiElementForWrite(myTargetClass.getContainingFile())) return; - PsiMethod method = createMethod(project); - List> arguments = - ContainerUtil.map2List(method.getParameterList().getParameters(), new Function>() { - public Pair fun(PsiParameter psiParameter) { - return Pair.create(null, psiParameter.getType()); - } - }); + PsiMethod method = createMethod(project); + List> arguments = + ContainerUtil.map2List(method.getParameterList().getParameters(), new Function>() { + public Pair fun(PsiParameter psiParameter) { + return Pair.create(null, psiParameter.getType()); + } + }); - method = (PsiMethod)JavaCodeStyleManager.getInstance(project).shortenClassReferences((PsiMethod)myTargetClass.add(method)); - CreateMethodFromUsageFix.doCreate(myTargetClass, method, arguments, PsiSubstitutor.EMPTY, ExpectedTypeInfo.EMPTY_ARRAY, method); - } - catch (IncorrectOperationException e) { - throw new RuntimeException(e); - } + method = (PsiMethod)JavaCodeStyleManager.getInstance(project).shortenClassReferences((PsiMethod)myTargetClass.add(method)); + CreateMethodFromUsageFix.doCreate(myTargetClass, method, arguments, PsiSubstitutor.EMPTY, ExpectedTypeInfo.EMPTY_ARRAY, method); } private PsiMethod createMethod(Project project) { diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/OrderEntryFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/OrderEntryFix.java index 0c1b429466db..9c9e93c96193 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/OrderEntryFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/OrderEntryFix.java @@ -22,6 +22,7 @@ import com.intellij.codeInsight.daemon.impl.actions.AddImportAction; import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.codeInspection.LocalQuickFix; import com.intellij.codeInspection.ProblemDescriptor; +import com.intellij.compiler.ModuleCompilerUtil; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.PathManager; import com.intellij.openapi.application.Result; @@ -42,8 +43,6 @@ import com.intellij.psi.*; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiUtil; -import com.intellij.util.IncorrectOperationException; -import com.intellij.compiler.ModuleCompilerUtil; import gnu.trove.THashSet; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -72,12 +71,7 @@ public abstract class OrderEntryFix implements IntentionAction, LocalQuickFix { } public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) { - try { - invoke(project, null, descriptor.getPsiElement().getContainingFile()); - } - catch (IncorrectOperationException e) { - throw new RuntimeException(e); - } + invoke(project, null, descriptor.getPsiElement().getContainingFile()); } @Nullable diff --git a/java/java-impl/src/com/intellij/codeInsight/editorActions/JavadocTypedHandler.java b/java/java-impl/src/com/intellij/codeInsight/editorActions/JavadocTypedHandler.java index f8de3b44ae76..8e792448c65f 100644 --- a/java/java-impl/src/com/intellij/codeInsight/editorActions/JavadocTypedHandler.java +++ b/java/java-impl/src/com/intellij/codeInsight/editorActions/JavadocTypedHandler.java @@ -117,6 +117,11 @@ public class JavadocTypedHandler extends TypedHandlerDelegate { return null; } return text.subSequence(i + 1, endOffset).toString(); + + // There is a possible case that opening tag has attributes, e.g. [offset]. We want to extract + // only tag name then. + case ' ': + case '\t': endOffset = i; } } return null; diff --git a/java/java-impl/src/com/intellij/ide/structureView/impl/StructureNodeRenderer.java b/java/java-impl/src/com/intellij/ide/structureView/impl/StructureNodeRenderer.java index 74af60cec239..35cc77e12166 100644 --- a/java/java-impl/src/com/intellij/ide/structureView/impl/StructureNodeRenderer.java +++ b/java/java-impl/src/com/intellij/ide/structureView/impl/StructureNodeRenderer.java @@ -23,6 +23,7 @@ import com.intellij.openapi.roots.ui.util.ModifiableCellAppearance; import com.intellij.openapi.util.Iconable; import com.intellij.psi.*; import com.intellij.psi.util.PsiFormatUtil; +import com.intellij.psi.util.PsiFormatUtilBase; import com.intellij.ui.ColoredTreeCellRenderer; import com.intellij.ui.SimpleTextAttributes; @@ -51,7 +52,8 @@ public class StructureNodeRenderer extends ColoredTreeCellRenderer { ModifiableCellAppearance result; if (psiElement instanceof PsiElement && !((PsiElement)psiElement).isValid()) { result = CompositeAppearance.single(name); - } else { + } + else { PsiClass psiClass = getContainingClass(psiElement); if (isInheritedMember(node, psiClass) && psiClass != null) { CompositeAppearance.DequeEnd ending = new CompositeAppearance().getEnding(); @@ -84,13 +86,13 @@ public class StructureNodeRenderer extends ColoredTreeCellRenderer { } } - public static String getNameOf(PsiElement psiElement) { + private static String getNameOf(PsiElement psiElement) { if (psiElement instanceof PsiMethod) return PsiFormatUtil.formatMethod((PsiMethod)psiElement, PsiSubstitutor.EMPTY, - PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_TYPE | PsiFormatUtil.TYPE_AFTER | - PsiFormatUtil.SHOW_PARAMETERS, - PsiFormatUtil.SHOW_TYPE + PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.TYPE_AFTER | + PsiFormatUtilBase.SHOW_PARAMETERS, + PsiFormatUtilBase.SHOW_TYPE ); return psiElement.toString(); } @@ -109,23 +111,17 @@ public class StructureNodeRenderer extends ColoredTreeCellRenderer { return new SimpleTextAttributes(nameAttributes.getStyle() | SimpleTextAttributes.STYLE_STRIKEOUT, nameAttributes.getFgColor()); } - public static boolean isDeprecated(Object psiElement) { - if (psiElement instanceof PsiDocCommentOwner) - return ((PsiDocCommentOwner) psiElement).isDeprecated(); - return false; + private static boolean isDeprecated(Object psiElement) { + return psiElement instanceof PsiDocCommentOwner && ((PsiDocCommentOwner)psiElement).isDeprecated(); } - public static PsiClass getContainingClass(Object element) { + private static PsiClass getContainingClass(Object element) { if (element instanceof PsiMember) return ((PsiMember) element).getContainingClass(); - if (element instanceof PsiClass) { - PsiElement parent = ((PsiClass) element).getParent(); - return (PsiClass) (parent instanceof PsiClass ? parent : null); - } return null; } - public static PsiClass getTreeParentClass(Object value) { + private static PsiClass getTreeParentClass(Object value) { if (!(value instanceof TreeNode)) return null; for (TreeNode treeNode = ((TreeNode) value).getParent(); treeNode != null; treeNode = treeNode.getParent()) { diff --git a/java/java-impl/src/com/intellij/ide/structureView/impl/java/JavaClassTreeElement.java b/java/java-impl/src/com/intellij/ide/structureView/impl/java/JavaClassTreeElement.java index b97433a98ca3..80951de253bd 100644 --- a/java/java-impl/src/com/intellij/ide/structureView/impl/java/JavaClassTreeElement.java +++ b/java/java-impl/src/com/intellij/ide/structureView/impl/java/JavaClassTreeElement.java @@ -35,10 +35,8 @@ public class JavaClassTreeElement extends JavaClassTreeElementBase { } private Collection getClassChildren() { - ArrayList array = new ArrayList(); - final PsiClass aClass = getElement(); - if (aClass == null) return array; + if (aClass == null) return Collections.emptyList(); List children = Arrays.asList(aClass.getChildren()); Collection ownChildren = new THashSet(); @@ -47,6 +45,7 @@ public class JavaClassTreeElement extends JavaClassTreeElementBase { ContainerUtil.addAll(ownChildren, aClass.getInnerClasses()); ContainerUtil.addAll(ownChildren, aClass.getInitializers()); Collection inherited = new LinkedHashSet(children); + List array = new ArrayList(inherited.size()); aClass.processDeclarations(new AddAllMembersProcessor(inherited, aClass), ResolveState.initial(), null, aClass); diff --git a/java/java-impl/src/com/intellij/ide/structureView/impl/java/JavaFileTreeElement.java b/java/java-impl/src/com/intellij/ide/structureView/impl/java/JavaFileTreeElement.java index 1a5bb59cf538..98a587a369c2 100644 --- a/java/java-impl/src/com/intellij/ide/structureView/impl/java/JavaFileTreeElement.java +++ b/java/java-impl/src/com/intellij/ide/structureView/impl/java/JavaFileTreeElement.java @@ -26,7 +26,6 @@ import java.util.ArrayList; import java.util.Collection; public class JavaFileTreeElement extends PsiTreeElementBase implements ItemPresentation { - public JavaFileTreeElement(PsiJavaFile file) { super(file); } diff --git a/java/java-impl/src/com/intellij/pom/java/impl/PomJavaAspectImpl.java b/java/java-impl/src/com/intellij/pom/java/impl/PomJavaAspectImpl.java index 9d128cb0c178..e3d0276469e1 100644 --- a/java/java-impl/src/com/intellij/pom/java/impl/PomJavaAspectImpl.java +++ b/java/java-impl/src/com/intellij/pom/java/impl/PomJavaAspectImpl.java @@ -68,7 +68,7 @@ public class PomJavaAspectImpl extends PomJavaAspect implements ProjectComponent if(changeSet == null) return; final PsiFile containingFile = changeSet.getRootElement().getPsi().getContainingFile(); if(!(containingFile.getLanguage() instanceof JavaLanguage)) return; - final PomJavaAspectChangeSet set = new PomJavaAspectChangeSet(myPomModel, containingFile); + final PomJavaAspectChangeSet set = new PomJavaAspectChangeSet(myPomModel); set.addChange(new JavaTreeChanged(containingFile)); event.registerChangeSet(this, set); } diff --git a/java/java-impl/testSrc/com/intellij/codeInsight/editorActions/JavadocTypedHandlerTest.java b/java/java-impl/testSrc/com/intellij/codeInsight/editorActions/JavadocTypedHandlerTest.java index 891157c1bdaa..b5935250a698 100644 --- a/java/java-impl/testSrc/com/intellij/codeInsight/editorActions/JavadocTypedHandlerTest.java +++ b/java/java-impl/testSrc/com/intellij/codeInsight/editorActions/JavadocTypedHandlerTest.java @@ -37,6 +37,12 @@ public class JavadocTypedHandlerTest { doTest("", null); } + @Test + public void tagWithAttribute() { + doTest("", "a"); + //TODO den implement + } + private static void doTest(String text, String expected) { StringBuilder normalized = new StringBuilder(); int offset = text.indexOf(CARET_MARKER); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondMisc.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondMisc.java index 30b750e35c9f..d802f473b299 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondMisc.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondMisc.java @@ -42,4 +42,28 @@ class Test1 { } class FF extends F{} -class F {} \ No newline at end of file +class F {} + +class MyTest { + static class Foo { + Foo(X x) {} + } + + static interface Base {} + static class A extends Exception implements Base {} + static class B extends Exception implements Base {} + + void m() throws B { + try { + if (true) { + throw new A(); + } + else { + throw new B(); + } + } catch (A ex) { + Foo> foo1 = new Foo<>(ex); // ok + Foo> foo2 = new Foo<>(ex); // should be error + } + } +} 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 1439b3b55f83..64ed0eedb9e9 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy @@ -429,9 +429,9 @@ class JavaAutoPopupTest extends CompletionAutoPopupTestCase { public void testVerticalArrows() { testArrows false, false, 0, -1 - testArrows false, true, -1, 1 - testArrows true, false, 0, -1 - testArrows true, true, -1, 1 + testArrows false, true, 0, -1 + testArrows true, false, 0, 1 + testArrows true, true, 0, 1 } public void testHideOnOnePrefixVariant() { diff --git a/java/java-tests/testSrc/com/intellij/openapi/vfs/LocalFileSystemTest.java b/java/java-tests/testSrc/com/intellij/openapi/vfs/LocalFileSystemTest.java index 820ddfd6d8d6..017070824b74 100644 --- a/java/java-tests/testSrc/com/intellij/openapi/vfs/LocalFileSystemTest.java +++ b/java/java-tests/testSrc/com/intellij/openapi/vfs/LocalFileSystemTest.java @@ -1,14 +1,19 @@ package com.intellij.openapi.vfs; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.vfs.impl.win32.Win32LocalFileSystem; import com.intellij.openapi.vfs.newvfs.ManagingFS; import com.intellij.testFramework.IdeaTestCase; import com.intellij.testFramework.IdeaTestUtil; +import org.jetbrains.annotations.NonNls; import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; +import java.io.OutputStreamWriter; +import java.nio.charset.Charset; import java.util.Arrays; public class LocalFileSystemTest extends IdeaTestCase{ @@ -219,4 +224,20 @@ public class LocalFileSystemTest extends IdeaTestCase{ ); } + + public static void setContentOnDisk(File file, byte[] bom, String content, Charset charset) throws IOException { + FileOutputStream stream = new FileOutputStream(file); + stream.write(bom); + OutputStreamWriter writer = new OutputStreamWriter(stream, charset); + writer.write(content); + writer.close(); + } + + public static VirtualFile createTempFile(@NonNls String ext, byte[] bom, @NonNls String content, Charset charset) throws IOException { + File temp = FileUtil.createTempFile("copy", "." + ext); + setContentOnDisk(temp, bom, content, charset); + + myFilesToDelete.add(temp); + return LocalFileSystem.getInstance().refreshAndFindFileByIoFile(temp); + } } diff --git a/java/java-tests/testSrc/com/intellij/projectView/StructureViewUpdatingTest.java b/java/java-tests/testSrc/com/intellij/projectView/StructureViewUpdatingTest.java index d7ee434b124c..81a61b14b0ad 100644 --- a/java/java-tests/testSrc/com/intellij/projectView/StructureViewUpdatingTest.java +++ b/java/java-tests/testSrc/com/intellij/projectView/StructureViewUpdatingTest.java @@ -34,11 +34,9 @@ package com.intellij.projectView; import com.intellij.JavaTestUtil; import com.intellij.ide.structureView.impl.java.InheritedMembersFilter; import com.intellij.ide.structureView.newStructureView.StructureViewComponent; -import com.intellij.openapi.projectRoots.Sdk; -import com.intellij.openapi.projectRoots.impl.JavaSdkImpl; -import com.intellij.testFramework.IdeaTestUtil; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.CommandProcessor; +import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.editor.Document; import com.intellij.openapi.fileEditor.FileEditor; import com.intellij.openapi.fileEditor.FileEditorManager; @@ -48,6 +46,7 @@ import com.intellij.psi.JavaDirectoryService; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiField; +import com.intellij.testFramework.PlatformTestUtil; import com.intellij.testFramework.TestSourceBasedTestCase; import com.intellij.util.IncorrectOperationException; @@ -69,55 +68,55 @@ public class StructureViewUpdatingTest extends TestSourceBasedTestCase { final StructureViewComponent structureViewComponent = (StructureViewComponent)fileEditor.getStructureViewBuilder().createStructureView(fileEditor, myProject); final Document document = PsiDocumentManager.getInstance(myProject).getDocument(psiClass.getContainingFile()); - IdeaTestUtil.assertTreeEqual(structureViewComponent.getTree(), - "-Class1.java\n" + - " -Class1\n" + - " getValue():int\n" + - " getClass():Class\n" + - " hashCode():int\n" + - " equals(Object):boolean\n" + - " clone():Object\n" + - " toString():String\n" + - " notify():void\n" + - " notifyAll():void\n" + - " wait(long):void\n" + - " wait(long, int):void\n" + - " wait():void\n" + - " finalize():void\n" + - " myField1:boolean\n" + - " myField2:boolean\n"); + PlatformTestUtil.assertTreeEqual(structureViewComponent.getTree(), + "-Class1.java\n" + + " -Class1\n" + + " getValue():int\n" + + " getClass():Class\n" + + " hashCode():int\n" + + " equals(Object):boolean\n" + + " clone():Object\n" + + " toString():String\n" + + " notify():void\n" + + " notifyAll():void\n" + + " wait(long):void\n" + + " wait(long, int):void\n" + + " wait():void\n" + + " finalize():void\n" + + " myField1:boolean\n" + + " myField2:boolean\n"); - CommandProcessor.getInstance().executeCommand(myProject, new Runnable() { + new WriteCommandAction.Simple(getProject()) { @Override - public void run() { - + protected void run() throws Throwable { final int offset = document.getLineStartOffset(5); document.insertString(offset, " boolean myNewField = false;\n"); } - }, null, null); + }.execute().throwException(); + PsiDocumentManager.getInstance(myProject).commitDocument(document); - IdeaTestUtil.waitForAlarm(600); + PlatformTestUtil.waitForAlarm(600); //TreeUtil.expand(structureViewComponent.getTree(), 3); - IdeaTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class1.java\n" + - " -Class1\n" + " getValue():int\n" + - " getClass():Class\n" + - " hashCode():int\n" + - " equals(Object):boolean\n" + - " clone():Object\n" + - " toString():String\n" + - " notify():void\n" + - " notifyAll():void\n" + - " wait(long):void\n" + - " wait(long, int):void\n" + - " wait():void\n" + - " finalize():void\n" + - " myField1:boolean\n" + - " myField2:boolean\n" + - " myNewField:boolean = false\n"); + PlatformTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class1.java\n" + + " -Class1\n" + " getValue():int\n" + + " getClass():Class\n" + + " hashCode():int\n" + + " equals(Object):boolean\n" + + " clone():Object\n" + + " toString():String\n" + + " notify():void\n" + + " notifyAll():void\n" + + " wait(long):void\n" + + " wait(long, int):void\n" + + " wait():void\n" + + " finalize():void\n" + + " myField1:boolean\n" + + " myField2:boolean\n" + + " myNewField:boolean = false\n"); Disposer.dispose(structureViewComponent); @@ -138,31 +137,31 @@ public class StructureViewUpdatingTest extends TestSourceBasedTestCase { try { structureViewComponent.setActionActive(InheritedMembersFilter.ID, true); - IdeaTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class2.java\n" + - " -Class2\n" + - " +InnerClass1\n" + - " +InnerClass2\n" + - " getValue():int\n" + - " myField1:boolean\n" + - " myField2:boolean\n" + - " myField3:boolean\n" + - " myField4:boolean\n"); + PlatformTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class2.java\n" + + " -Class2\n" + + " +InnerClass1\n" + + " +InnerClass2\n" + + " getValue():int\n" + + " myField1:boolean\n" + + " myField2:boolean\n" + + " myField3:boolean\n" + + " myField4:boolean\n"); final PsiField innerClassField = psiClass.getInnerClasses()[0].getFields()[0]; structureViewComponent.select(innerClassField, true); - IdeaTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class2.java\n" + - " -Class2\n" + - " -InnerClass1\n" + - " +InnerClass12\n" + - " myInnerClassField:int\n" + - " +InnerClass2\n" + - " getValue():int\n" + - " myField1:boolean\n" + - " myField2:boolean\n" + - " myField3:boolean\n" + - " myField4:boolean\n"); + PlatformTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class2.java\n" + + " -Class2\n" + + " -InnerClass1\n" + + " +InnerClass12\n" + + " myInnerClassField:int\n" + + " +InnerClass2\n" + + " getValue():int\n" + + " myField1:boolean\n" + + " myField2:boolean\n" + + " myField3:boolean\n" + + " myField4:boolean\n"); CommandProcessor.getInstance().executeCommand(myProject, new Runnable() { @Override @@ -175,25 +174,25 @@ public class StructureViewUpdatingTest extends TestSourceBasedTestCase { innerClassField.delete(); } catch (IncorrectOperationException e) { - assertTrue(e.getLocalizedMessage(), false); + fail(e.getLocalizedMessage()); } } }); } }, null, null); - IdeaTestUtil.waitForAlarm(600); + PlatformTestUtil.waitForAlarm(600); - IdeaTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class2.java\n" + - " -Class2\n" + - " -InnerClass1\n" + - " +InnerClass12\n" + - " +InnerClass2\n" + - " getValue():int\n" + - " myField1:boolean\n" + - " myField2:boolean\n" + - " myField3:boolean\n" + - " myField4:boolean\n"); + PlatformTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class2.java\n" + + " -Class2\n" + + " -InnerClass1\n" + + " +InnerClass12\n" + + " +InnerClass2\n" + + " getValue():int\n" + + " myField1:boolean\n" + + " myField2:boolean\n" + + " myField3:boolean\n" + + " myField4:boolean\n"); } finally { @@ -213,26 +212,26 @@ public class StructureViewUpdatingTest extends TestSourceBasedTestCase { (StructureViewComponent)fileEditor.getStructureViewBuilder().createStructureView(fileEditor, myProject); final JTree tree = structureViewComponent.getTree(); - IdeaTestUtil.assertTreeEqual(tree, "-test.xml\n" + - " -test\n" + - " +level1\n" + - " +level1\n" + - " +level1\n" + - " +level1\n"); + PlatformTestUtil.assertTreeEqual(tree, "-test.xml\n" + + " -test\n" + + " +level1\n" + + " +level1\n" + + " +level1\n" + + " +level1\n"); tree.expandPath(tree.getPathForRow(3)); - IdeaTestUtil.waitForAlarm(600); + PlatformTestUtil.waitForAlarm(600); - IdeaTestUtil.assertTreeEqual(tree, - "-test.xml\n" + - " -test\n" + - " +level1\n" + - " -level1\n" + - " +level2\n" + - " +level1\n" + - " +level1\n"); + PlatformTestUtil.assertTreeEqual(tree, + "-test.xml\n" + + " -test\n" + + " +level1\n" + + " -level1\n" + + " +level2\n" + + " +level1\n" + + " +level1\n"); Disposer.dispose(structureViewComponent); } @@ -246,4 +245,9 @@ public class StructureViewUpdatingTest extends TestSourceBasedTestCase { protected String getTestDataPath() { return JavaTestUtil.getJavaTestDataPath(); } + + @Override + protected boolean isRunInWriteAction() { + return false; + } } diff --git a/java/openapi/src/com/intellij/pom/java/events/PomJavaAspectChangeSet.java b/java/openapi/src/com/intellij/pom/java/events/PomJavaAspectChangeSet.java index d1e2792219f9..2625a48a6144 100644 --- a/java/openapi/src/com/intellij/pom/java/events/PomJavaAspectChangeSet.java +++ b/java/openapi/src/com/intellij/pom/java/events/PomJavaAspectChangeSet.java @@ -20,7 +20,6 @@ import com.intellij.pom.PomModel; import com.intellij.pom.PomModelAspect; import com.intellij.pom.event.PomChangeSet; import com.intellij.pom.java.PomJavaAspect; -import com.intellij.psi.PsiFile; import java.util.ArrayList; import java.util.List; @@ -28,22 +27,16 @@ import java.util.List; public class PomJavaAspectChangeSet implements PomChangeSet{ private final PomModel myModel; private final List myChanges = new ArrayList(); - private final PsiFile myChangedFile; - public PomJavaAspectChangeSet(PomModel model, PsiFile fileChanged) { + public PomJavaAspectChangeSet(PomModel model) { myModel = model; - myChangedFile = fileChanged; } public void addChange(PomJavaChange change) { myChanges.add(change); } - public List getChanges() { - return myChanges; - } - public PomModelAspect getAspect() { return myModel.getModelAspect(PomJavaAspect.class); } @@ -53,8 +46,4 @@ public class PomJavaAspectChangeSet implements PomChangeSet{ final PomJavaAspectChangeSet blockedJavaChange = (PomJavaAspectChangeSet)blocked; myChanges.addAll(blockedJavaChange.myChanges); } - - public PsiFile getChangedFile() { - return myChangedFile; - } } diff --git a/java/testFramework/src/com/intellij/projectView/BaseProjectViewTestCase.java b/java/testFramework/src/com/intellij/projectView/BaseProjectViewTestCase.java index cbe0eb8c9a30..c1c6510b24d3 100644 --- a/java/testFramework/src/com/intellij/projectView/BaseProjectViewTestCase.java +++ b/java/testFramework/src/com/intellij/projectView/BaseProjectViewTestCase.java @@ -25,8 +25,6 @@ import com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode; import com.intellij.ide.util.treeView.*; import com.intellij.openapi.application.ex.PathManagerEx; import com.intellij.openapi.project.DumbAwareRunnable; -import com.intellij.openapi.projectRoots.Sdk; -import com.intellij.openapi.projectRoots.impl.JavaSdkImpl; import com.intellij.openapi.startup.StartupManager; import com.intellij.openapi.ui.Queryable; import com.intellij.openapi.util.Disposer; @@ -300,4 +298,9 @@ public abstract class BaseProjectViewTestCase extends TestSourceBasedTestCase { protected String getTestDataPath() { return PathManagerEx.getTestDataPath(getClass()); } + + @Override + protected boolean isRunInWriteAction() { + return false; + } } diff --git a/platform/lang-api/src/com/intellij/analysis/AnalysisScope.java b/platform/lang-api/src/com/intellij/analysis/AnalysisScope.java index 9460a5791b6b..b7fc38cdbc95 100644 --- a/platform/lang-api/src/com/intellij/analysis/AnalysisScope.java +++ b/platform/lang-api/src/com/intellij/analysis/AnalysisScope.java @@ -237,7 +237,9 @@ public class AnalysisScope { protected void accept(final PsiElementVisitor visitor, final boolean needReadAction) { if (myType == VIRTUAL_FILES) { final PsiManager psiManager = PsiManager.getInstance(myProject); + final FileIndex index = ProjectRootManager.getInstance(myProject).getFileIndex(); for (final VirtualFile file : myFilesSet) { + if (!myIncludeTestSource && index.isInTestSourceContent(file)) continue; if (!processFile(file, visitor, psiManager, needReadAction)) return; } } else if (myScope instanceof GlobalSearchScope) { @@ -247,6 +249,7 @@ public class AnalysisScope { public boolean processFile(final VirtualFile fileOrDir) { final boolean isInScope = ApplicationManager.getApplication().runReadAction(new Computable() { public Boolean compute() { + if (!myIncludeTestSource && projectFileIndex.isInTestSourceContent(fileOrDir)) return false; return ((GlobalSearchScope)myScope).contains(fileOrDir); } }).booleanValue(); 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 106e016d7b86..c2f09f4c935c 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java @@ -239,11 +239,10 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler { @NotNull private LookupImpl obtainLookup(Editor editor) { LookupImpl existing = (LookupImpl)LookupManager.getActiveLookup(editor); - if (existing != null && existing.isCompletion()) { + if (existing != null && existing.isCompletion() && !existing.isHintMode()) { existing.markReused(); if (!autopopup) { existing.setFocused(true); - existing.setHintMode(false); } return existing; } 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 de8e1eb23ab0..b00d961853ef 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 @@ -17,6 +17,7 @@ package com.intellij.codeInsight.lookup.impl; import com.intellij.codeInsight.lookup.LookupManager; +import com.intellij.ide.ui.UISettings; import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Editor; @@ -73,11 +74,6 @@ public abstract class LookupActionHandler extends EditorActionHandler { protected void executeInLookup(final LookupImpl lookup, DataContext context) { if (!lookup.isFocused()) { - if (lookup.isPositionedAboveCaret()) { - myOriginalHandler.execute(lookup.getEditor(), context); - return; - } - lookup.setFocused(true); lookup.getList().setSelectedIndex(0); lookup.refreshUi(); @@ -94,16 +90,14 @@ public abstract class LookupActionHandler extends EditorActionHandler { protected void executeInLookup(final LookupImpl lookup, DataContext context) { if (!lookup.isFocused()) { - if (!lookup.isPositionedAboveCaret()) { + if (!UISettings.getInstance().CYCLE_SCROLLING) { myOriginalHandler.execute(lookup.getEditor(), context); return; } lookup.setFocused(true); - final int index = ApplicationManager.getApplication().isUnitTestMode() ? lookup.getItems().size() - 1 : lookup.getList().getLastVisibleIndex(); - lookup.getList().setSelectedIndex(index); + lookup.getList().setSelectedIndex(0); lookup.refreshUi(); - return; } ListScrollingUtil.moveUp(lookup.getList(), 0); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/actions/ChooseItemReplaceAction.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/actions/ChooseItemReplaceAction.java index 54c84064dc0a..53a3fe3acd77 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/actions/ChooseItemReplaceAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/actions/ChooseItemReplaceAction.java @@ -22,6 +22,7 @@ import com.intellij.codeInsight.completion.CompletionService; import com.intellij.codeInsight.lookup.Lookup; import com.intellij.codeInsight.lookup.LookupManager; import com.intellij.codeInsight.lookup.impl.LookupImpl; +import com.intellij.codeInsight.template.impl.ListTemplatesHandler; import com.intellij.codeInsight.template.impl.LiveTemplateCompletionContributor; import com.intellij.codeInsight.template.impl.TemplateImpl; import com.intellij.codeInsight.template.impl.TemplateSettings; @@ -51,6 +52,8 @@ public class ChooseItemReplaceAction extends EditorAction { public boolean isEnabled(Editor editor, DataContext dataContext) { LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor); if (lookup != null) { + lookup.refreshUi(); // to bring the list model up to date + CompletionProcess completion = CompletionService.getCompletionService().getCurrentCompletion(); if (completion != null && completion.isAutopopupCompletion() && hasTemplatePrefix(lookup, TemplateSettings.TAB_CHAR)) { return false; @@ -60,7 +63,6 @@ public class ChooseItemReplaceAction extends EditorAction { return true; } - lookup.refreshUi(); // to bring the list model up to date return !lookup.getItems().isEmpty(); } return false; @@ -76,7 +78,7 @@ public class ChooseItemReplaceAction extends EditorAction { final int end = editor.getCaretModel().getOffset(); final int start = lookup.getLookupStart(); - final String prefix = editor.getDocument().getText(TextRange.create(start, end)); + final String prefix = !lookup.getItems().isEmpty() ? editor.getDocument().getText(TextRange.create(start, end)) : ListTemplatesHandler.getPrefix(editor.getDocument(), end); final TemplateImpl template = LiveTemplateCompletionContributor.findApplicableTemplate(file, end, prefix); return template != null && shortcutChar == TemplateSettings.getInstance().getShortcutChar(template); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/ListTemplatesHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/ListTemplatesHandler.java index 2d2e49487640..12a3b0760a57 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/ListTemplatesHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/ListTemplatesHandler.java @@ -107,7 +107,7 @@ public class ListTemplatesHandler implements CodeInsightActionHandler { return true; } - private static String getPrefix(Document document, int offset) { + public static String getPrefix(Document document, int offset) { CharSequence chars = document.getCharsSequence(); int start = offset; while (true) { diff --git a/platform/lang-impl/src/com/intellij/codeInspection/actions/RunInspectionAction.java b/platform/lang-impl/src/com/intellij/codeInspection/actions/RunInspectionAction.java index b5dbefcb4d96..0e074c0538a9 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/actions/RunInspectionAction.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/actions/RunInspectionAction.java @@ -27,20 +27,16 @@ import com.intellij.codeInspection.ex.InspectionProfileImpl; import com.intellij.featureStatistics.FeatureUsageTracker; import com.intellij.ide.IdeBundle; import com.intellij.ide.actions.GotoActionBase; +import com.intellij.ide.util.gotoByName.ChooseByNameFilter; import com.intellij.ide.util.gotoByName.ChooseByNamePopup; -import com.intellij.ide.util.gotoByName.ChooseByNamePopupComponent; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.LangDataKeys; import com.intellij.openapi.actionSystem.PlatformDataKeys; -import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleUtil; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.PsiDirectory; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiManager; +import com.intellij.psi.*; import org.jdom.Element; import org.jetbrains.annotations.NotNull; @@ -57,26 +53,30 @@ public class RunInspectionAction extends GotoActionBase { @Override protected void gotoActionPerformed(final AnActionEvent e) { final Project project = e.getData(PlatformDataKeys.PROJECT); + if (project == null) return; + + PsiDocumentManager.getInstance(project).commitAllDocuments(); + final PsiElement psiElement = LangDataKeys.PSI_ELEMENT.getData(e.getDataContext()); final PsiFile psiFile = LangDataKeys.PSI_FILE.getData(e.getDataContext()); final VirtualFile virtualFile = LangDataKeys.VIRTUAL_FILE.getData(e.getDataContext()); - if (project == null || virtualFile == null) return; + if (virtualFile == null) return; + FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.goto.inspection"); - final ChooseByNamePopup popup = ChooseByNamePopup.createPopup(project, new GotoInspectionModel(project), getPsiContext(e)); - popup.setSearchInAnyPlace(true); - popup.invoke(new ChooseByNamePopupComponent.Callback() { - public void onClose() { - if (RunInspectionAction.class.equals(myInAction)) { - myInAction = null; - } + final GotoInspectionModel model = new GotoInspectionModel(project); + showNavigationPopup(e, model, new GotoActionCallback() { + @Override + protected ChooseByNameFilter createFilter(ChooseByNamePopup popup) { + popup.setSearchInAnyPlace(true); + return super.createFilter(popup); } - public void elementChosen(Object element) { - final InspectionProfileEntry profileEntry = (InspectionProfileEntry)element; - runInspection(project, profileEntry, virtualFile, psiElement, psiFile); + @Override + public void elementChosen(ChooseByNamePopup popup, Object element) { + runInspection(project, (InspectionProfileEntry)element, virtualFile, psiElement, psiFile); } - }, ModalityState.current(), true); + }); } private static void runInspection(@NotNull Project project, diff --git a/platform/lang-impl/src/com/intellij/execution/runners/ConsoleExecuteActionHandler.java b/platform/lang-impl/src/com/intellij/execution/runners/ConsoleExecuteActionHandler.java index 6f4571eb3502..bbc4c9271ede 100644 --- a/platform/lang-impl/src/com/intellij/execution/runners/ConsoleExecuteActionHandler.java +++ b/platform/lang-impl/src/com/intellij/execution/runners/ConsoleExecuteActionHandler.java @@ -57,10 +57,10 @@ public class ConsoleExecuteActionHandler { } public void processLine(String line) { - sendLine(line + "\n"); + sendText(line + "\n"); } - public void sendLine(String line) { + public void sendText(String line) { //final Charset charset = myProcessHandler.getCharset(); final OutputStream outputStream = myProcessHandler.getProcessInput(); try { diff --git a/platform/lang-impl/src/com/intellij/ide/actions/GotoActionAction.java b/platform/lang-impl/src/com/intellij/ide/actions/GotoActionAction.java index 94df0b906239..aea4d046417c 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/GotoActionAction.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/GotoActionAction.java @@ -19,7 +19,6 @@ package com.intellij.ide.actions; import com.intellij.featureStatistics.FeatureUsageTracker; import com.intellij.ide.DataManager; import com.intellij.ide.util.gotoByName.ChooseByNamePopup; -import com.intellij.ide.util.gotoByName.ChooseByNamePopupComponent; import com.intellij.ide.util.gotoByName.GotoActionModel; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.actionSystem.ex.ActionUtil; @@ -38,15 +37,9 @@ public class GotoActionAction extends GotoActionBase implements DumbAware { FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.popup.action"); - final ChooseByNamePopup popup = ChooseByNamePopup.createPopup(project, new GotoActionModel(project, component), getPsiContext(e)); - popup.invoke(new ChooseByNamePopupComponent.Callback() { - public void onClose() { - if (GotoActionAction.class.equals(myInAction)) { - myInAction = null; - } - } - - public void elementChosen(Object element) { + showNavigationPopup(e, new GotoActionModel(project, component), new GotoActionCallback() { + @Override + public void elementChosen(ChooseByNamePopup popup, Object element) { final AnAction action = (AnAction)((Map.Entry)element).getKey(); if (action != null) { ApplicationManager.getApplication().invokeLater(new Runnable() { @@ -62,7 +55,7 @@ public class GotoActionAction extends GotoActionBase implements DumbAware { }, ModalityState.NON_MODAL); } } - }, ModalityState.current(), true); + }); } } \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/ide/actions/GotoActionBase.java b/platform/lang-impl/src/com/intellij/ide/actions/GotoActionBase.java index 4c69b3a20065..d55ddc3209ce 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/GotoActionBase.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/GotoActionBase.java @@ -16,7 +16,12 @@ package com.intellij.ide.actions; +import com.intellij.ide.util.gotoByName.ChooseByNameFilter; +import com.intellij.ide.util.gotoByName.ChooseByNameModel; +import com.intellij.ide.util.gotoByName.ChooseByNamePopup; +import com.intellij.ide.util.gotoByName.ChooseByNamePopupComponent; import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; @@ -25,6 +30,10 @@ import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; +import org.jetbrains.annotations.Nullable; + +import java.util.HashMap; +import java.util.Map; /** * Author: msk @@ -33,17 +42,8 @@ public abstract class GotoActionBase extends AnAction { private static final Logger LOG = Logger.getInstance("#com.intellij.ide.actions.GotoActionBase"); protected static Class myInAction = null; + private static Map ourLastStrings = new HashMap(); - public static String getInitialText(Editor editor) { - if (editor == null) { - return ""; - } - final String selectedText = editor.getSelectionModel().getSelectedText(); - if (selectedText != null && selectedText.indexOf("\n") < 0) { - return selectedText; - } - return ""; - } public final void actionPerformed(AnActionEvent e) { LOG.assertTrue (!getClass ().equals (myInAction)); @@ -71,6 +71,7 @@ public abstract class GotoActionBase extends AnAction { return true; } + @Nullable public static PsiElement getPsiContext(final AnActionEvent e) { PsiFile file = e.getData(LangDataKeys.PSI_FILE); if (file != null) return file; @@ -78,6 +79,7 @@ public abstract class GotoActionBase extends AnAction { return getPsiContext(project); } + @Nullable public static PsiElement getPsiContext(final Project project) { if (project == null) return null; Editor selectedEditor = FileEditorManager.getInstance(project).getSelectedTextEditor(); @@ -85,4 +87,58 @@ public abstract class GotoActionBase extends AnAction { Document document = selectedEditor.getDocument(); return PsiDocumentManager.getInstance(project).getPsiFile(document); } + + protected static abstract class GotoActionCallback { + @Nullable + protected ChooseByNameFilter createFilter(ChooseByNamePopup popup) { + return null; + } + + public abstract void elementChosen(ChooseByNamePopup popup, Object element); + } + + private static String getInitialText(Editor editor) { + if (editor != null) { + final String selectedText = editor.getSelectionModel().getSelectedText(); + if (selectedText != null && selectedText.indexOf("\n") < 0) { + return selectedText; + } + } + + if (myInAction != null) { + final String lastString = ourLastStrings.get(myInAction); + if (lastString != null) { + return lastString; + } + } + + return ""; + } + + protected static void showNavigationPopup(AnActionEvent e, ChooseByNameModel model, final GotoActionCallback callback) { + final Project project = e.getData(PlatformDataKeys.PROJECT); + + final Class startedAction = myInAction; + final ChooseByNamePopup popup = ChooseByNamePopup.createPopup(project, model, getPsiContext(e), getInitialText(e.getData(PlatformDataKeys.EDITOR))); + final ChooseByNameFilter filter = callback.createFilter(popup); + popup.invoke(new ChooseByNamePopupComponent.Callback() { + + @Override + public void onClose() { + ourLastStrings.put(myInAction, popup.getEnteredText()); + if (startedAction.equals(myInAction)) { + myInAction = null; + } + if (filter != null) { + filter.close(); + } + } + + @Override + public void elementChosen(Object element) { + callback.elementChosen(popup, element); + } + }, ModalityState.current(), true); + + } } diff --git a/platform/lang-impl/src/com/intellij/ide/actions/GotoClassAction.java b/platform/lang-impl/src/com/intellij/ide/actions/GotoClassAction.java index 7dd49cbbf3c5..0e2923d92742 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/GotoClassAction.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/GotoClassAction.java @@ -19,12 +19,12 @@ package com.intellij.ide.actions; import com.intellij.codeInsight.navigation.NavigationUtil; import com.intellij.featureStatistics.FeatureUsageTracker; import com.intellij.ide.util.gotoByName.*; +import com.intellij.lang.Language; import com.intellij.navigation.ChooseByNameRegistry; import com.intellij.navigation.NavigationItem; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.actionSystem.PlatformDataKeys; -import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.DumbService; import com.intellij.openapi.project.Project; @@ -43,23 +43,18 @@ public class GotoClassAction extends GotoActionBase implements DumbAware { return; } - FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.popup.class"); PsiDocumentManager.getInstance(project).commitAllDocuments(); + FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.popup.class"); final GotoClassModel2 model = new GotoClassModel2(project); - final ChooseByNamePopup popup = ChooseByNamePopup.createPopup(project, model, getPsiContext(e), - getInitialText(e.getData(PlatformDataKeys.EDITOR))); - final ChooseByNameFilter filterUI = new ChooseByNameLanguageFilter(popup, model, GotoClassSymbolConfiguration.getInstance(project), project); - - popup.invoke(new ChooseByNamePopupComponent.Callback() { - public void onClose() { - if (GotoClassAction.class.equals(myInAction)) { - myInAction = null; - } - filterUI.close(); + showNavigationPopup(e, model, new GotoActionCallback() { + @Override + protected ChooseByNameFilter createFilter(ChooseByNamePopup popup) { + return new ChooseByNameLanguageFilter(popup, model, GotoClassSymbolConfiguration.getInstance(project), project); } - public void elementChosen(Object element) { + @Override + public void elementChosen(ChooseByNamePopup popup, Object element) { if (element instanceof PsiElement) { NavigationUtil.activateFileWithPsiElement((PsiElement)element); } @@ -67,7 +62,7 @@ public class GotoClassAction extends GotoActionBase implements DumbAware { ((NavigationItem)element).navigate(true); } } - }, ModalityState.current(), true); + }); } protected boolean hasContributors(DataContext dataContext) { diff --git a/platform/lang-impl/src/com/intellij/ide/actions/GotoFileAction.java b/platform/lang-impl/src/com/intellij/ide/actions/GotoFileAction.java index 823b1e8a7b72..4e79629b59b8 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/GotoFileAction.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/GotoFileAction.java @@ -17,7 +17,10 @@ package com.intellij.ide.actions; import com.intellij.featureStatistics.FeatureUsageTracker; -import com.intellij.ide.util.gotoByName.*; +import com.intellij.ide.util.gotoByName.ChooseByNameFilter; +import com.intellij.ide.util.gotoByName.ChooseByNamePopup; +import com.intellij.ide.util.gotoByName.GotoFileConfiguration; +import com.intellij.ide.util.gotoByName.GotoFileModel; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.application.ApplicationManager; @@ -52,18 +55,14 @@ public class GotoFileAction extends GotoActionBase implements DumbAware { FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.popup.file"); final Project project = e.getData(PlatformDataKeys.PROJECT); final GotoFileModel gotoFileModel = new GotoFileModel(project); - final ChooseByNamePopup popup = ChooseByNamePopup.createPopup(project, gotoFileModel, getPsiContext(e), - getInitialText(e.getData(PlatformDataKeys.EDITOR))); - final ChooseByNameFilter filterUI = new GotoFileFilter(popup, gotoFileModel, project); - popup.invoke(new ChooseByNamePopupComponent.Callback() { - public void onClose() { - if (GotoFileAction.class.equals(myInAction)) { - myInAction = null; - } - filterUI.close(); + showNavigationPopup(e, gotoFileModel, new GotoActionCallback() { + @Override + protected ChooseByNameFilter createFilter(ChooseByNamePopup popup) { + return new GotoFileFilter(popup, gotoFileModel, project); } - public void elementChosen(final Object element) { + @Override + public void elementChosen(final ChooseByNamePopup popup, final Object element) { if (element == null) return; ApplicationManager.getApplication().invokeLater(new Runnable() { public void run() { @@ -81,7 +80,7 @@ public class GotoFileAction extends GotoActionBase implements DumbAware { } }, ModalityState.NON_MODAL); } - }, ModalityState.current(), true); + }); } protected static class GotoFileFilter extends ChooseByNameFilter { diff --git a/platform/lang-impl/src/com/intellij/ide/actions/GotoSymbolAction.java b/platform/lang-impl/src/com/intellij/ide/actions/GotoSymbolAction.java index ef2d7197d441..65ac622cf6ba 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/GotoSymbolAction.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/GotoSymbolAction.java @@ -18,12 +18,12 @@ package com.intellij.ide.actions; import com.intellij.featureStatistics.FeatureUsageTracker; import com.intellij.ide.util.gotoByName.*; -import com.intellij.navigation.NavigationItem; +import com.intellij.lang.Language; import com.intellij.navigation.ChooseByNameRegistry; +import com.intellij.navigation.NavigationItem; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.actionSystem.PlatformDataKeys; -import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDocumentManager; @@ -32,26 +32,19 @@ public class GotoSymbolAction extends GotoActionBase { public void gotoActionPerformed(AnActionEvent e) { FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.popup.symbol"); final Project project = e.getData(PlatformDataKeys.PROJECT); - - PsiDocumentManager.getInstance(project).commitAllDocuments(); - final GotoSymbolModel2 model = new GotoSymbolModel2(project); - final ChooseByNamePopup popup = ChooseByNamePopup.createPopup(project, model, getPsiContext(e), - getInitialText(e.getData(PlatformDataKeys.EDITOR))); - final ChooseByNameFilter filterUI = new ChooseByNameLanguageFilter(popup, model, GotoClassSymbolConfiguration.getInstance(project), - project); - popup.invoke(new ChooseByNamePopupComponent.Callback() { - public void onClose() { - if (GotoSymbolAction.class.equals(myInAction)) { - myInAction = null; - } - filterUI.close(); + PsiDocumentManager.getInstance(project).commitAllDocuments(); + showNavigationPopup(e, model, new GotoActionCallback() { + @Override + protected ChooseByNameFilter createFilter(ChooseByNamePopup popup) { + return new ChooseByNameLanguageFilter(popup, model, GotoClassSymbolConfiguration.getInstance(project), project); } - public void elementChosen(Object element) { + @Override + public void elementChosen(ChooseByNamePopup popup, Object element) { ((NavigationItem)element).navigate(true); } - }, ModalityState.current(), true); + }); } protected boolean hasContributors(DataContext dataContext) { diff --git a/platform/lang-impl/src/com/intellij/ide/fileTemplates/FileTemplateUtil.java b/platform/lang-impl/src/com/intellij/ide/fileTemplates/FileTemplateUtil.java index 77a277ac7546..92badac379be 100644 --- a/platform/lang-impl/src/com/intellij/ide/fileTemplates/FileTemplateUtil.java +++ b/platform/lang-impl/src/com/intellij/ide/fileTemplates/FileTemplateUtil.java @@ -311,7 +311,7 @@ public class FileTemplateUtil{ final Properties finalProps = props; CommandProcessor.getInstance().executeCommand(project, new Runnable(){ public void run(){ - final Runnable run = new Runnable(){ + ApplicationManager.getApplication().runWriteAction(new Runnable(){ public void run(){ try{ CreateFromTemplateHandler handler = findHandler(template); @@ -321,8 +321,7 @@ public class FileTemplateUtil{ commandException[0] = ex; } } - }; - ApplicationManager.getApplication().runWriteAction(run); + }); } }, template.isJavaClassTemplate() ? IdeBundle.message("command.create.class.from.template") diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/AbstractProjectViewPane.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/AbstractProjectViewPane.java index b5eba4485b24..c581147a1eaf 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/AbstractProjectViewPane.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/AbstractProjectViewPane.java @@ -74,7 +74,7 @@ import java.util.List; import java.util.Map; -public abstract class AbstractProjectViewPane implements DataProvider, Disposable { +public abstract class AbstractProjectViewPane implements DataProvider, Disposable, BusyObject { public static ExtensionPointName EP_NAME = ExtensionPointName.create("com.intellij.projectViewPane"); protected final Project myProject; @@ -635,4 +635,9 @@ public abstract class AbstractProjectViewPane implements DataProvider, Disposabl } return false; } + + @Override + public ActionCallback getReady(Object requestor) { + return myTreeBuilder.getUi().getReady(requestor); + } } diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java index 61d5dc90cf70..b72c14c6b5bd 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java @@ -116,7 +116,7 @@ import java.util.List; file = "$WORKSPACE_FILE$" )} ) -public final class ProjectViewImpl extends ProjectView implements PersistentStateComponent, Disposable, QuickActionProvider { +public final class ProjectViewImpl extends ProjectView implements PersistentStateComponent, Disposable, QuickActionProvider, BusyObject { private static final Logger LOG = Logger.getInstance("#com.intellij.ide.projectView.impl.ProjectViewImpl"); private final CopyPasteDelegator myCopyPasteDelegator; private boolean isInitialized; @@ -577,6 +577,7 @@ public final class ProjectViewImpl extends ProjectView implements PersistentStat if (toolWindow != null) { final ContentManager contentManager = toolWindow.getContentManager(); final Content content = contentManager.getFactory().createContent(getComponent(), ToolWindowId.PROJECT_VIEW, false); + content.setBusyObject(this); contentManager.addContent(content); content.setPreferredFocusedComponent(new Computable() { @@ -1836,4 +1837,10 @@ public final class ProjectViewImpl extends ProjectView implements PersistentStat ensurePanesLoaded(); return mySelectInTargets.values(); } + + @Override + public ActionCallback getReady(Object requestor) { + AbstractProjectViewPane pane = myId2Pane.get(myCurrentViewSubId); + return pane != null ? pane.getReady(requestor) : new ActionCallback.Done(); + } } diff --git a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java index 169a393956a8..53a2008b05a2 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java +++ b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java @@ -447,6 +447,9 @@ public abstract class ChooseByNameBase { case KeyEvent.VK_PAGE_DOWN: ListScrollingUtil.movePageDown(myList); break; + case KeyEvent.VK_TAB: + close(true); + break; case KeyEvent.VK_ENTER: if (myList.getSelectedValue() == EXTRA_ELEM) { myMaximumListSizeLimit += MAXIMUM_LIST_SIZE_LIMIT; @@ -992,7 +995,7 @@ public abstract class ChooseByNameBase { myCompletionKeyStroke = getShortcut(IdeActions.ACTION_CODE_COMPLETION); forwardStroke = getShortcut(IdeActions.ACTION_GOTO_FORWARD); backStroke = getShortcut(IdeActions.ACTION_GOTO_BACK); - + setFocusTraversalKeysEnabled(false); } private KeyStroke getShortcut(String actionCodeCompletion) { diff --git a/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureGestureDetector.java b/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureGestureDetector.java index 189f15b8742a..0caed03d9f5c 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureGestureDetector.java +++ b/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureGestureDetector.java @@ -199,7 +199,9 @@ public class ChangeSignatureGestureDetector extends PsiTreeChangeAdapter impleme if (changeBean != null && changeBean.getInitialText() != null) { final Editor editor = myFileEditorManager.getSelectedTextEditor(); if (editor != null && myTemplateManager.getActiveTemplate(editor) != null) return; - if (LanguageChangeSignatureDetectors.INSTANCE.forLanguage(child.getLanguage()).ignoreChanges(child)) return; + final LanguageChangeSignatureDetector detector = LanguageChangeSignatureDetectors.INSTANCE.forLanguage(child.getLanguage()); + if (detector == null) return; + if (detector.ignoreChanges(child)) return; final ChangeInfo info = LanguageChangeSignatureDetectors.createCurrentChangeInfo(child, changeBean.getInitialChangeInfo()); if (info == null) { changeBean.reinit(); diff --git a/platform/lang-impl/src/com/intellij/refactoring/inline/GenericInlineHandler.java b/platform/lang-impl/src/com/intellij/refactoring/inline/GenericInlineHandler.java index bbc2945dac1a..875bee27ff72 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/inline/GenericInlineHandler.java +++ b/platform/lang-impl/src/com/intellij/refactoring/inline/GenericInlineHandler.java @@ -38,6 +38,7 @@ import com.intellij.usageView.UsageInfo; import com.intellij.util.containers.HashMap; import com.intellij.util.containers.HashSet; import com.intellij.util.containers.MultiMap; +import org.jetbrains.annotations.Nullable; import java.util.*; @@ -47,8 +48,8 @@ import java.util.*; @SuppressWarnings({"UtilityClassWithoutPrivateConstructor"}) public class GenericInlineHandler { - public static boolean invoke(final PsiElement element, final Editor editor, final InlineHandler languageSpecific) { - final PsiReference invocationReference = TargetElementUtilBase.findReference(editor); + public static boolean invoke(final PsiElement element, @Nullable Editor editor, final InlineHandler languageSpecific) { + final PsiReference invocationReference = editor != null ? TargetElementUtilBase.findReference(editor) : null; final InlineHandler.Settings settings = languageSpecific.prepareInlineElement(element, editor, invocationReference != null); if (settings == null || settings == InlineHandler.Settings.CANNOT_INLINE_SETTINGS) { return settings != null; @@ -65,7 +66,7 @@ public class GenericInlineHandler { public void run() { usagesRef.set(ReferencesSearch.search(element).findAll()); } - }, "Find Usages", false, editor.getProject()); + }, "Find Usages", false, element.getProject()); allReferences = usagesRef.get(); } diff --git a/platform/lang-impl/src/com/intellij/refactoring/inline/InlineRefactoringActionHandler.java b/platform/lang-impl/src/com/intellij/refactoring/inline/InlineRefactoringActionHandler.java index 4bd9427af015..db3ccfa481a9 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/inline/InlineRefactoringActionHandler.java +++ b/platform/lang-impl/src/com/intellij/refactoring/inline/InlineRefactoringActionHandler.java @@ -38,6 +38,7 @@ import com.intellij.refactoring.RefactoringActionHandler; import com.intellij.refactoring.RefactoringBundle; import com.intellij.refactoring.util.CommonRefactoringUtil; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; @@ -57,6 +58,8 @@ public class InlineRefactoringActionHandler implements RefactoringActionHandler return; } } + + invokeInliner(editor, elements[0]); } public void invoke(@NotNull final Project project, Editor editor, PsiFile file, DataContext dataContext) { @@ -78,7 +81,7 @@ public class InlineRefactoringActionHandler implements RefactoringActionHandler } } - public static boolean invokeInliner(Editor editor, PsiElement element) { + public static boolean invokeInliner(@Nullable Editor editor, PsiElement element) { final List handlers = InlineHandlers.getInlineHandlers(element.getLanguage()); for (InlineHandler handler : handlers) { if (GenericInlineHandler.invoke(element, editor, handler)) { diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java index d54a659b2deb..07591f7c4d6f 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java @@ -102,8 +102,9 @@ public class FileBasedIndex implements ApplicationComponent { private final Set myNoLimitCheckTypes = new HashSet(); private final PerIndexDocumentMap myLastIndexedDocStamps = new PerIndexDocumentMap() { + @NotNull @Override - protected Long createDefault(Document document) { + protected Long createDefault(@NotNull Document document) { return 0L; } }; @@ -1161,7 +1162,7 @@ public class FileBasedIndex implements ApplicationComponent { } // returns false if doc was not indexed because the file does not fit in scope - private boolean indexUnsavedDocument(final Document document, final ID requestedIndexId, final Project project, GlobalSearchScope filter) throws StorageException { + private boolean indexUnsavedDocument(@NotNull final Document document, @NotNull final ID requestedIndexId, final Project project, GlobalSearchScope filter) throws StorageException { final VirtualFile vFile = myFileDocumentManager.getFile(document); if (!(vFile instanceof VirtualFileWithId) || !vFile.isValid()) { return true; @@ -1253,9 +1254,7 @@ public class FileBasedIndex implements ApplicationComponent { } private void cleanupMemoryStorage() { - synchronized (myLastIndexedDocStamps) { - myLastIndexedDocStamps.clear(); - } + myLastIndexedDocStamps.clear(); for (ID indexId : myIndices.keySet()) { final MapReduceIndex index = (MapReduceIndex)getIndex(indexId); assert index != null; diff --git a/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUpdater.java b/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUpdater.java index c076a99d3013..a6bfe1507455 100644 --- a/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUpdater.java +++ b/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUpdater.java @@ -86,7 +86,7 @@ public class AbstractTreeUpdater implements Disposable, Activatable { } public boolean hasNodesToUpdate() { - return myNodeQueue.size() > 0 || !myUpdateQueue.isEmpty(); + return !myNodeQueue.isEmpty() || !myUpdateQueue.isEmpty(); } public void dispose() { @@ -114,15 +114,15 @@ public class AbstractTreeUpdater implements Disposable, Activatable { toAdd.expire(); break; } - else if (passInQueue.getNode() == toAdd.getNode()) { + if (passInQueue.getNode() == toAdd.getNode()) { toAdd.expire(); break; } - else if (toAdd.getNode().isNodeAncestor(passInQueue.getNode())) { + if (toAdd.getNode().isNodeAncestor(passInQueue.getNode())) { toAdd.expire(); break; } - else if (passInQueue.getNode().isNodeAncestor(toAdd.getNode())) { + if (passInQueue.getNode().isNodeAncestor(toAdd.getNode())) { iterator.remove(); passInQueue.expire(); } @@ -133,9 +133,7 @@ public class AbstractTreeUpdater implements Disposable, Activatable { if (!toAdd.isExpired()) { final Collection yielding = ui.getYeildingPasses(); - for (Iterator iterator = yielding.iterator(); iterator.hasNext();) { - TreeUpdatePass eachYielding = iterator.next(); - + for (TreeUpdatePass eachYielding : yielding) { final DefaultMutableTreeNode eachNode = eachYielding.getCurrentNode(); if (eachNode != null) { if (eachNode.isNodeAncestor(toAdd.getNode())) { @@ -228,8 +226,7 @@ public class AbstractTreeUpdater implements Disposable, Activatable { try { myTreeBuilder.getUi().updateSubtreeNow(eachPass, false); } - catch (ProcessCanceledException e) { - return; + catch (ProcessCanceledException ignored) { } } }); @@ -348,10 +345,8 @@ public class AbstractTreeUpdater implements Disposable, Activatable { } public boolean isEnqueuedToUpdate(DefaultMutableTreeNode node) { - Iterator nodes = myNodeQueue.iterator(); - while (nodes.hasNext()) { - TreeUpdatePass each = nodes.next(); - if (each.willUpdate(node)) return true; + for (TreeUpdatePass pass : myNodeQueue) { + if (pass.willUpdate(node)) return true; } return false; } diff --git a/platform/platform-api/src/com/intellij/openapi/wm/ToolWindow.java b/platform/platform-api/src/com/intellij/openapi/wm/ToolWindow.java index 12aca9181a42..93870283c6ce 100644 --- a/platform/platform-api/src/com/intellij/openapi/wm/ToolWindow.java +++ b/platform/platform-api/src/com/intellij/openapi/wm/ToolWindow.java @@ -16,6 +16,7 @@ package com.intellij.openapi.wm; import com.intellij.openapi.util.ActionCallback; +import com.intellij.openapi.util.BusyObject; import com.intellij.openapi.util.Key; import com.intellij.ui.content.ContentManager; import org.jetbrains.annotations.NotNull; @@ -26,7 +27,7 @@ import javax.swing.border.EmptyBorder; import java.awt.*; import java.awt.event.InputEvent; -public interface ToolWindow { +public interface ToolWindow extends BusyObject { Key SHOW_CONTENT_ICON = new Key("ContentIcon"); diff --git a/platform/platform-api/src/com/intellij/ui/AutoScrollToSourceHandler.java b/platform/platform-api/src/com/intellij/ui/AutoScrollToSourceHandler.java index fa9496738462..d42881301d22 100644 --- a/platform/platform-api/src/com/intellij/ui/AutoScrollToSourceHandler.java +++ b/platform/platform-api/src/com/intellij/ui/AutoScrollToSourceHandler.java @@ -25,8 +25,11 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.fileTypes.FileTypeManager; import com.intellij.openapi.fileTypes.FileTypes; import com.intellij.openapi.project.DumbAware; +import com.intellij.openapi.util.ActionCallback; +import com.intellij.openapi.util.BusyObject; import com.intellij.openapi.util.IconLoader; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.wm.ToolWindow; import com.intellij.pom.Navigatable; import com.intellij.util.Alarm; import com.intellij.util.OpenSourceUtil; @@ -140,22 +143,28 @@ public abstract class AutoScrollToSourceHandler { protected abstract boolean isAutoScrollMode(); protected abstract void setAutoScrollMode(boolean state); - protected void scrollToSource(Component tree) { + protected void scrollToSource(final Component tree) { DataContext dataContext=DataManager.getInstance().getDataContext(tree); - final VirtualFile vFile = PlatformDataKeys.VIRTUAL_FILE.getData(dataContext); - if (vFile != null) { - // Attempt to navigate to the virtual file with unknown file type will show a modal dialog - // asking to register some file type for this file. This behaviour is undesirable when autoscrolling. - if (FileTypeManager.getInstance().getFileTypeByFile(vFile) == FileTypes.UNKNOWN) return; - } - Navigatable[] navigatables = PlatformDataKeys.NAVIGATABLE_ARRAY.getData(dataContext); - if (navigatables != null) { - for (Navigatable navigatable : navigatables) { - // we are not going to open modal dialog during autoscrolling - if (!navigatable.canNavigateToSource()) return; + getReady(dataContext).doWhenDone(new Runnable() { + @Override + public void run() { + DataContext context = DataManager.getInstance().getDataContext(tree); + final VirtualFile vFile = PlatformDataKeys.VIRTUAL_FILE.getData(context); + if (vFile != null) { + // Attempt to navigate to the virtual file with unknown file type will show a modal dialog + // asking to register some file type for this file. This behaviour is undesirable when autoscrolling. + if (FileTypeManager.getInstance().getFileTypeByFile(vFile) == FileTypes.UNKNOWN) return; + } + Navigatable[] navigatables = PlatformDataKeys.NAVIGATABLE_ARRAY.getData(context); + if (navigatables != null) { + for (Navigatable navigatable : navigatables) { + // we are not going to open modal dialog during autoscrolling + if (!navigatable.canNavigateToSource()) return; + } + } + OpenSourceUtil.openSourcesFrom(context, false); } - } - OpenSourceUtil.openSourcesFrom(dataContext, false); + }); } public ToggleAction createToggleAction() { @@ -175,5 +184,10 @@ public abstract class AutoScrollToSourceHandler { setAutoScrollMode(flag); } } + + private ActionCallback getReady(DataContext context) { + ToolWindow toolWindow = PlatformDataKeys.TOOL_WINDOW.getData(context); + return toolWindow != null ? toolWindow.getReady(this) : new ActionCallback.Done(); + } } diff --git a/platform/platform-api/src/com/intellij/ui/content/Content.java b/platform/platform-api/src/com/intellij/ui/content/Content.java index e0b134bcccd6..68c6d96ace9c 100644 --- a/platform/platform-api/src/com/intellij/ui/content/Content.java +++ b/platform/platform-api/src/com/intellij/ui/content/Content.java @@ -18,6 +18,7 @@ package com.intellij.ui.content; import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.ActionGroup; import com.intellij.openapi.ui.ComponentContainer; +import com.intellij.openapi.util.BusyObject; import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.UserDataHolder; import org.jetbrains.annotations.NonNls; @@ -102,5 +103,9 @@ public interface Content extends UserDataHolder, ComponentContainer { @Nullable AlertIcon getAlertIcon(); void fireAlert(); - + + @Nullable + BusyObject getBusyObject(); + void setBusyObject(BusyObject object); + } diff --git a/platform/platform-api/src/com/intellij/ui/content/ContentManager.java b/platform/platform-api/src/com/intellij/ui/content/ContentManager.java index 75dbc3a17ac6..f3668b2da457 100644 --- a/platform/platform-api/src/com/intellij/ui/content/ContentManager.java +++ b/platform/platform-api/src/com/intellij/ui/content/ContentManager.java @@ -19,13 +19,14 @@ import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.DataProvider; import com.intellij.openapi.util.ActionCallback; +import com.intellij.openapi.util.BusyObject; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.util.List; -public interface ContentManager extends Disposable { +public interface ContentManager extends Disposable, BusyObject { boolean canCloseContents(); diff --git a/platform/platform-api/src/com/intellij/util/ui/update/MergingUpdateQueue.java b/platform/platform-api/src/com/intellij/util/ui/update/MergingUpdateQueue.java index bcb2e34055f7..c6fec60254d8 100644 --- a/platform/platform-api/src/com/intellij/util/ui/update/MergingUpdateQueue.java +++ b/platform/platform-api/src/com/intellij/util/ui/update/MergingUpdateQueue.java @@ -123,8 +123,7 @@ public class MergingUpdateQueue implements Runnable, Disposable, Activatable { try { each.setRejected(); } - catch (ProcessCanceledException e) { - continue; + catch (ProcessCanceledException ignored) { } } myScheduledUpdates.clear(); @@ -237,7 +236,7 @@ public class MergingUpdateQueue implements Runnable, Disposable, Activatable { } }; - if (myExecuteInDispatchThread && invokeLaterIfNotDispatch && !ApplicationManager.getApplication().isDispatchThread()) { + if (myExecuteInDispatchThread && invokeLaterIfNotDispatch) { UIUtil.invokeLaterIfNeeded(toRun); } else { @@ -394,7 +393,7 @@ public class MergingUpdateQueue implements Runnable, Disposable, Activatable { public boolean isEmpty() { synchronized (myScheduledUpdates) { - return myScheduledUpdates.size() == 0; + return myScheduledUpdates.isEmpty(); } } diff --git a/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java b/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java index e978cc84e260..f222cd4772cd 100644 --- a/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java +++ b/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java @@ -366,6 +366,12 @@ public class IdeEventQueue extends EventQueue { try { _dispatchEvent(e); + } catch (ProcessCanceledException pce) { + throw pce; + } catch (Throwable exc) { + if (!myToolkitBugsProcessor.process(exc)) { + LOG.error("Error during dispatching of " + e, exc); + } } finally { myIsInInputEvent = wasInputEvent; diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java index c8a218c3a956..91d6c9fb3ab1 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java @@ -365,7 +365,7 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener, EditorSettings editorSettings = myEditor.getSettings(); - if (!editorSettings.isVirtualSpace() && line < lineCount) { + if (!editorSettings.isVirtualSpace() && line < lineCount && !myEditor.getSelectionModel().hasBlockSelection()) { int lineEndOffset = doc.getLineEndOffset(line); int lineEndColumnNumber = myEditor.offsetToLogicalPosition(lineEndOffset).column; if (column > lineEndColumnNumber) { diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java index e2e5963c3d03..917e8d449be9 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java @@ -3258,7 +3258,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi return; } - if (!mySettings.isVirtualSpace()) { + if (!mySettings.isVirtualSpace() && !mySelectionModel.hasBlockSelection()) { int lineEndOffset = myDocument.getLineEndOffset(lineNumber); int lineEndColumnNumber = calcColumnNumber(lineEndOffset, lineNumber); if (columnNumber > lineEndColumnNumber) { diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/MarkupModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/MarkupModelImpl.java index ecce8d321218..04812916c5e3 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/MarkupModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/MarkupModelImpl.java @@ -24,6 +24,7 @@ */ package com.intellij.openapi.editor.impl; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.ex.MarkupModelEx; @@ -54,11 +55,13 @@ public class MarkupModelImpl extends UserDataHolderBase implements MarkupModelEx private final RangeHighlighterTree myHighlighterTree; MarkupModelImpl(DocumentImpl document) { + ApplicationManager.getApplication().assertIsDispatchThread(); myDocument = document; myHighlighterTree = new RangeHighlighterTree(myDocument); } public void dispose() { + ApplicationManager.getApplication().assertIsDispatchThread(); myHighlighterTree.dispose(); } @@ -98,9 +101,11 @@ public class MarkupModelImpl extends UserDataHolderBase implements MarkupModelEx @NotNull public RangeHighlighter[] getAllHighlighters() { + ApplicationManager.getApplication().assertIsDispatchThread(); if (myCachedHighlighters == null) { - if (myHighlighterTree.size() == 0) return RangeHighlighter.EMPTY_ARRAY; - List list = new ArrayList(); + int size = myHighlighterTree.size(); + if (size == 0) return RangeHighlighter.EMPTY_ARRAY; + List list = new ArrayList(size); myHighlighterTree.process(new CommonProcessors.CollectProcessor(list)); myCachedHighlighters = list.toArray(new RangeHighlighter[list.size()]); } @@ -115,6 +120,7 @@ public class MarkupModelImpl extends UserDataHolderBase implements MarkupModelEx @NotNull HighlighterTargetArea targetArea, boolean isPersistent, @Nullable Consumer changeAttributesAction) { + ApplicationManager.getApplication().assertIsDispatchThread(); RangeHighlighterEx highlighter = isPersistent ? new PersistentRangeHighlighterImpl(this, startOffset, layer, targetArea, textAttributes) : new RangeHighlighterImpl(this, startOffset, endOffset, layer, targetArea, textAttributes); @@ -134,6 +140,7 @@ public class MarkupModelImpl extends UserDataHolderBase implements MarkupModelEx @Override public void changeAttributesInBatch(@NotNull RangeHighlighterEx highlighter, @NotNull Consumer changeAttributesAction) { + ApplicationManager.getApplication().assertIsDispatchThread(); boolean changed = highlighter instanceof PersistentRangeHighlighterImpl ? ((PersistentRangeHighlighterImpl)highlighter).changeAttributesInBatch(changeAttributesAction) : ((RangeHighlighterImpl)highlighter).changeAttributesInBatch(changeAttributesAction); @@ -143,6 +150,7 @@ public class MarkupModelImpl extends UserDataHolderBase implements MarkupModelEx } void addRangeHighlighter(RangeHighlighterEx marker, int start, int end, RangeHighlighterData data) { + ApplicationManager.getApplication().assertIsDispatchThread(); myHighlighterTree.addInterval(marker, start, end, data); } @@ -156,6 +164,7 @@ public class MarkupModelImpl extends UserDataHolderBase implements MarkupModelEx } public void removeHighlighter(@NotNull RangeHighlighter segmentHighlighter) { + ApplicationManager.getApplication().assertIsDispatchThread(); myCachedHighlighters = null; if (!segmentHighlighter.isValid()) return; @@ -166,6 +175,7 @@ public class MarkupModelImpl extends UserDataHolderBase implements MarkupModelEx } public void removeAllHighlighters() { + ApplicationManager.getApplication().assertIsDispatchThread(); myHighlighterTree.process(new Processor() { public boolean process(RangeMarkerEx rangeMarkerEx) { fireBeforeRemoved((RangeHighlighterEx)rangeMarkerEx); @@ -191,6 +201,7 @@ public class MarkupModelImpl extends UserDataHolderBase implements MarkupModelEx } public void setRangeHighlighterAttributes(@NotNull final RangeHighlighter highlighter, final TextAttributes textAttributes) { + ApplicationManager.getApplication().assertIsDispatchThread(); ((RangeHighlighterImpl)highlighter).setTextAttributes(textAttributes); } @@ -211,6 +222,7 @@ public class MarkupModelImpl extends UserDataHolderBase implements MarkupModelEx } public boolean containsHighlighter(@NotNull final RangeHighlighter highlighter) { + ApplicationManager.getApplication().assertIsDispatchThread(); return !myHighlighterTree.processOverlappingWith(highlighter.getStartOffset(), highlighter.getEndOffset(), new Processor() { public boolean process(RangeHighlighterEx h) { return h.getId() != ((RangeHighlighterEx)highlighter).getId(); @@ -236,6 +248,7 @@ public class MarkupModelImpl extends UserDataHolderBase implements MarkupModelEx } public void normalize() { + ApplicationManager.getApplication().assertIsDispatchThread(); myHighlighterTree.normalize(); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowHeadlessManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowHeadlessManagerImpl.java index 6d976bc72805..0f37f3b72fbd 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowHeadlessManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowHeadlessManagerImpl.java @@ -71,7 +71,11 @@ public class ToolWindowHeadlessManagerImpl extends ToolWindowManagerEx { public boolean isVisible() { return false; } - + + @Override + public ActionCallback getReady(Object requestor) { + return new ActionCallback.Done(); + } public void show(@Nullable Runnable runnable) { } @@ -175,6 +179,12 @@ public class ToolWindowHeadlessManagerImpl extends ToolWindowManagerEx { }; @NonNls private static final ContentManager MOCK_CONTENT_MANAGER = new ContentManager() { + + @Override + public ActionCallback getReady(Object requestor) { + return new ActionCallback.Done(); + } + public void addContent(@NotNull final Content content) { } public void addContent(@NotNull Content content, int order) { } public void addContent(@NotNull final Content content, final Object constraints) { } diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowImpl.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowImpl.java index f84197091b98..a5ecf97f5c77 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowImpl.java @@ -20,16 +20,18 @@ import com.intellij.openapi.actionSystem.ActionGroup; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.util.ActionCallback; -import com.intellij.openapi.wm.ToolWindowAnchor; -import com.intellij.openapi.wm.ToolWindowContentUiType; -import com.intellij.openapi.wm.ToolWindowFactory; -import com.intellij.openapi.wm.ToolWindowType; +import com.intellij.openapi.util.BusyObject; +import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.wm.*; import com.intellij.openapi.wm.ex.ToolWindowEx; +import com.intellij.openapi.wm.impl.commands.FinalizableCommand; import com.intellij.openapi.wm.impl.content.ToolWindowContentUi; import com.intellij.ui.content.Content; import com.intellij.ui.content.ContentFactory; import com.intellij.ui.content.ContentManager; import com.intellij.ui.content.impl.ContentImpl; +import com.intellij.util.ui.update.Activatable; +import com.intellij.util.ui.update.UiNotifyConnector; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -38,6 +40,7 @@ import java.awt.*; import java.awt.event.InputEvent; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; +import java.util.ArrayList; /** * @author Anton Katilin @@ -62,6 +65,12 @@ public final class ToolWindowImpl implements ToolWindowEx { private ToolWindowFactory myContentFactory; private ActionCallback myActivation = new ActionCallback.Done(); + private BusyObject.Impl myShowing = new BusyObject.Impl() { + @Override + protected boolean isReady() { + return myComponent != null && myComponent.isShowing(); + } + }; ToolWindowImpl(final ToolWindowManagerImpl toolWindowManager, final String id, boolean canCloseContent, @Nullable final JComponent component) { myToolWindowManager = toolWindowManager; @@ -81,6 +90,14 @@ public final class ToolWindowImpl implements ToolWindowEx { } myComponent = myContentManager.getComponent(); + + UiNotifyConnector notifyConnector = new UiNotifyConnector(myComponent, new Activatable.Adapter() { + @Override + public void showNotify() { + myShowing.onReady(); + } + }); + Disposer.register(myContentManager, notifyConnector); } public final void addPropertyChangeListener(final PropertyChangeListener l) { @@ -117,6 +134,30 @@ public final class ToolWindowImpl implements ToolWindowEx { return myToolWindowManager.isToolWindowActive(myId) || (myDecorator != null && myDecorator.isFocused()); } + @Override + public ActionCallback getReady(final Object requestor) { + final ActionCallback result = new ActionCallback(); + myShowing.getReady(this).doWhenDone(new Runnable() { + @Override + public void run() { + ArrayList cmd = new ArrayList(); + cmd.add(new FinalizableCommand(null) { + @Override + public void run() { + IdeFocusManager.getInstance(myToolWindowManager.getProject()).doWhenFocusSettlesDown(new Runnable() { + @Override + public void run() { + myContentManager.getReady(requestor).notify(result); + } + }); + } + }); + myToolWindowManager.execute(cmd); + } + }); + return result; + } + public final void show(final Runnable runnable) { ApplicationManager.getApplication().assertIsDispatchThread(); myToolWindowManager.showToolWindow(myId); diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java index e02c51fc3a5c..a9528c3256c9 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java @@ -558,7 +558,7 @@ public final class ToolWindowManagerImpl extends ToolWindowManagerEx implements * This is helper method. It delegated its fuctionality to the WindowManager. * Before delegating it fires state changed. */ - private void execute(final ArrayList commandList) { + public void execute(final ArrayList commandList) { for (FinalizableCommand each : commandList) { if (each.willChangeState()) { fireStateChanged(); diff --git a/platform/platform-impl/src/com/intellij/ui/content/impl/ContentImpl.java b/platform/platform-impl/src/com/intellij/ui/content/impl/ContentImpl.java index 4487d294804a..d345f257b02c 100644 --- a/platform/platform-impl/src/com/intellij/ui/content/impl/ContentImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/content/impl/ContentImpl.java @@ -18,10 +18,7 @@ package com.intellij.ui.content.impl; import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.ActionGroup; -import com.intellij.openapi.util.Computable; -import com.intellij.openapi.util.Disposer; -import com.intellij.openapi.util.IconLoader; -import com.intellij.openapi.util.UserDataHolderBase; +import com.intellij.openapi.util.*; import com.intellij.ui.LayeredIcon; import com.intellij.ui.content.AlertIcon; import com.intellij.ui.content.Content; @@ -57,6 +54,7 @@ public class ContentImpl extends UserDataHolderBase implements Content { private JComponent mySearchComponent; private Computable myFocusRequest; + private BusyObject myBusyObject; public ContentImpl(JComponent component, String displayName, boolean isPinnable) { myComponent = component; @@ -264,6 +262,16 @@ public class ContentImpl extends UserDataHolderBase implements Content { myChangeSupport.firePropertyChange(PROP_ALERT, null, true); } + @Override + public void setBusyObject(BusyObject object) { + myBusyObject = object; + } + + @Override + public BusyObject getBusyObject() { + return myBusyObject; + } + public void setSearchComponent(@Nullable final JComponent comp) { mySearchComponent = comp; } diff --git a/platform/platform-impl/src/com/intellij/ui/content/impl/ContentManagerImpl.java b/platform/platform-impl/src/com/intellij/ui/content/impl/ContentManagerImpl.java index 2e3707e37bb0..f47c0df6739f 100644 --- a/platform/platform-impl/src/com/intellij/ui/content/impl/ContentManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/content/impl/ContentManagerImpl.java @@ -23,10 +23,7 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.ActionCallback; -import com.intellij.openapi.util.ActiveRunnable; -import com.intellij.openapi.util.Comparing; -import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.util.*; import com.intellij.openapi.wm.FocusCommand; import com.intellij.openapi.wm.IdeFocusManager; import com.intellij.openapi.wm.ex.IdeFocusTraversalPolicy; @@ -109,6 +106,13 @@ public class ContentManagerImpl implements ContentManager, PropertyChangeListene return myComponent; } + @Override + public ActionCallback getReady(Object requestor) { + Content selected = getSelectedContent(); + BusyObject busyObject = selected.getBusyObject(); + return busyObject != null ? busyObject.getReady(requestor) : new ActionCallback.Done(); + } + private class MyContentComponent extends NonOpaquePanel implements DataProvider, SwitchProvider { private final List myProviders = new ArrayList(); diff --git a/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java b/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java index ee6627924f92..e455ec2534fe 100644 --- a/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java +++ b/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java @@ -15,7 +15,8 @@ */ package com.intellij.testFramework; -import com.intellij.ide.*; +import com.intellij.ide.DataManager; +import com.intellij.ide.IdeEventQueue; import com.intellij.ide.util.treeView.AbstractTreeNode; import com.intellij.ide.util.treeView.AbstractTreeStructure; import com.intellij.idea.Bombed; @@ -48,9 +49,10 @@ import org.jetbrains.annotations.TestOnly; import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreePath; -import java.util.*; import java.awt.*; import java.awt.event.InvocationEvent; +import java.util.*; +import java.util.concurrent.atomic.AtomicBoolean; /** @@ -99,14 +101,14 @@ public class PlatformTestUtil { } public static String print(JTree tree, boolean withSelection, Condition nodePrintCondition) { - StringBuffer buffer = new StringBuffer(); + StringBuilder buffer = new StringBuilder(); Object root = tree.getModel().getRoot(); printImpl(tree, root, buffer, 0, withSelection, nodePrintCondition); return buffer.toString(); } - private static void printImpl(JTree tree, Object root, StringBuffer buffer, int level, boolean withSelection, @Nullable Condition nodePrintCondition) { + private static void printImpl(JTree tree, Object root, StringBuilder buffer, int level, boolean withSelection, @Nullable Condition nodePrintCondition) { DefaultMutableTreeNode defaultMutableTreeNode = (DefaultMutableTreeNode)root; @@ -116,7 +118,7 @@ public class PlatformTestUtil { nodeText = toString(userObject, null); } else { - nodeText = defaultMutableTreeNode + ""; + nodeText = String.valueOf(defaultMutableTreeNode); } @@ -163,8 +165,10 @@ public class PlatformTestUtil { Assert.assertEquals(expected, treeStringPresentation); } + @TestOnly public static void waitForAlarm(final int delay) throws InterruptedException { - final boolean[] invoked = new boolean[]{false}; + assert !ApplicationManager.getApplication().isWriteAccessAllowed(): "It's a bad idea to wait for an alarm under the write action. Somebody creates an alarm which requires read action and you are deadlocked."; + final AtomicBoolean invoked = new AtomicBoolean(); final Alarm alarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD); alarm.addRequest(new Runnable() { @Override @@ -175,7 +179,7 @@ public class PlatformTestUtil { alarm.addRequest(new Runnable() { @Override public void run() { - invoked[0] = true; + invoked.set(true); } }, delay); } @@ -185,10 +189,13 @@ public class PlatformTestUtil { UIUtil.dispatchAllInvocationEvents(); - while (!invoked[0]) { + boolean sleptAlready = false; + while (!invoked.get()) { UIUtil.dispatchAllInvocationEvents(); - Thread.sleep(delay); + Thread.sleep(sleptAlready ? 10 : delay); + sleptAlready = true; } + UIUtil.dispatchAllInvocationEvents(); } @TestOnly diff --git a/platform/usageView/src/com/intellij/usages/impl/GroupNode.java b/platform/usageView/src/com/intellij/usages/impl/GroupNode.java index 583fce9f8caa..991a365e5f9c 100644 --- a/platform/usageView/src/com/intellij/usages/impl/GroupNode.java +++ b/platform/usageView/src/com/intellij/usages/impl/GroupNode.java @@ -105,7 +105,10 @@ public class GroupNode extends Node implements Navigatable, Comparable { T thing = myQueue.poll(); if (thing == null) break; if (!myProcessor.process(thing)) { - myQueue.clear(); + stop(); return; } processed++; diff --git a/plugins/ant/src/com/intellij/lang/ant/config/impl/AntConfigurationImpl.java b/plugins/ant/src/com/intellij/lang/ant/config/impl/AntConfigurationImpl.java index cefc93e4dcfe..c20ac8d33c29 100644 --- a/plugins/ant/src/com/intellij/lang/ant/config/impl/AntConfigurationImpl.java +++ b/plugins/ant/src/com/intellij/lang/ant/config/impl/AntConfigurationImpl.java @@ -343,9 +343,9 @@ public class AntConfigurationImpl extends AntConfigurationBase implements Persis return null; } for (ExecutionEvent ev : events) { - final String presentableName = ev.getPresentableName(); - if (Comparing.strEqual(targetName, presentableName)) { - return new MetaTarget(buildFile, presentableName, ((ExecuteCompositeTargetEvent)ev).getTargetNames()); + final String name = ExecuteCompositeTargetEvent.TYPE_ID.equals(ev.getTypeId())? ((ExecuteCompositeTargetEvent)ev).getMetaTargetName() : ev.getPresentableName(); + if (Comparing.strEqual(targetName, name)) { + return new MetaTarget(buildFile, ev.getPresentableName(), ((ExecuteCompositeTargetEvent)ev).getTargetNames()); } } return null; diff --git a/xml/impl/src/com/intellij/xml/breadcrumbs/BreadcrumbsLoaderComponent.java b/xml/impl/src/com/intellij/xml/breadcrumbs/BreadcrumbsLoaderComponent.java index 236d5cd730c4..17d5aa1007da 100644 --- a/xml/impl/src/com/intellij/xml/breadcrumbs/BreadcrumbsLoaderComponent.java +++ b/xml/impl/src/com/intellij/xml/breadcrumbs/BreadcrumbsLoaderComponent.java @@ -48,20 +48,20 @@ public class BreadcrumbsLoaderComponent extends AbstractProjectComponent { return webEditorOptions.isBreadcrumbsEnabled() || webEditorOptions.isBreadcrumbsEnabledInXml(); } - private static class MyFileEditorManagerListener implements FileEditorManagerListener { + private static class MyFileEditorManagerListener extends FileEditorManagerAdapter { public void fileOpened(final FileEditorManager source, final VirtualFile file) { if (isEnabled() && isSuitable(source.getProject(), file)) { final FileEditor[] fileEditors = source.getEditors(file); - for (final FileEditor each : fileEditors) { - if (each instanceof TextEditor) { - final BreadcrumbsXmlWrapper wrapper = new BreadcrumbsXmlWrapper(((TextEditor)each).getEditor()); + for (final FileEditor fileEditor : fileEditors) { + if (fileEditor instanceof TextEditor) { + final BreadcrumbsXmlWrapper wrapper = new BreadcrumbsXmlWrapper(((TextEditor)fileEditor).getEditor()); final JComponent c = wrapper.getComponent(); - source.addTopComponent(each, c); + source.addTopComponent(fileEditor, c); - Disposer.register(each, wrapper); - Disposer.register(each, new Disposable() { + Disposer.register(fileEditor, wrapper); + Disposer.register(fileEditor, new Disposable() { public void dispose() { - source.removeTopComponent(each, c); + source.removeTopComponent(fileEditor, c); } }); } @@ -74,11 +74,11 @@ public class BreadcrumbsLoaderComponent extends AbstractProjectComponent { return false; } - final FileViewProvider psiFile = PsiManager.getInstance(project).findViewProvider(file); + final FileViewProvider provider = PsiManager.getInstance(project).findViewProvider(file); - return psiFile != null - && hasNonEmptyHtml(psiFile) - && BreadcrumbsXmlWrapper.findInfoProvider(psiFile) != null; + return provider != null + && hasNonEmptyHtml(provider) + && BreadcrumbsXmlWrapper.findInfoProvider(provider) != null; } public static boolean hasNonEmptyHtml(FileViewProvider viewProvider) { @@ -94,11 +94,5 @@ public class BreadcrumbsLoaderComponent extends AbstractProjectComponent { } return false; } - - public void fileClosed(final FileEditorManager source, final VirtualFile file) { - } - - public void selectionChanged(final FileEditorManagerEvent event) { - } } } diff --git a/xml/impl/src/com/intellij/xml/breadcrumbs/BreadcrumbsXmlWrapper.java b/xml/impl/src/com/intellij/xml/breadcrumbs/BreadcrumbsXmlWrapper.java index 95b2b2815ecd..ea00e02f2023 100644 --- a/xml/impl/src/com/intellij/xml/breadcrumbs/BreadcrumbsXmlWrapper.java +++ b/xml/impl/src/com/intellij/xml/breadcrumbs/BreadcrumbsXmlWrapper.java @@ -34,13 +34,6 @@ import com.intellij.openapi.util.TextRange; import com.intellij.openapi.vcs.FileStatusListener; import com.intellij.openapi.vcs.FileStatusManager; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.pom.PomManager; -import com.intellij.pom.PomModelAspect; -import com.intellij.pom.event.PomChangeSet; -import com.intellij.pom.event.PomModelEvent; -import com.intellij.pom.event.PomModelListener; -import com.intellij.pom.xml.XmlAspect; -import com.intellij.pom.xml.XmlChangeSet; import com.intellij.psi.*; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.update.MergingUpdateQueue; @@ -103,8 +96,7 @@ public class BreadcrumbsXmlWrapper implements BreadcrumbsItemListener(); myComponent.addBreadcrumbsItemListener(this); @@ -140,8 +153,7 @@ public class BreadcrumbsXmlWrapper implements BreadcrumbsItemListener