Merge branch 'master' of git.labs.intellij.net:idea/community

This commit is contained in:
Maxim Medvedev
2011-02-21 18:47:19 +03:00
58 changed files with 595 additions and 386 deletions
@@ -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();
}
@@ -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() {
+1
View File
@@ -4,6 +4,7 @@
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/testSrc" isTestSource="true" />
</content>
<orderEntry type="module" module-name="boot" />
<orderEntry type="inheritedJdk" />
@@ -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<Pair<PsiExpression, PsiType>> arguments =
ContainerUtil.map2List(method.getParameterList().getParameters(), new Function<PsiParameter, Pair<PsiExpression, PsiType>>() {
public Pair<PsiExpression, PsiType> fun(PsiParameter psiParameter) {
return Pair.create(null, psiParameter.getType());
}
});
PsiMethod method = createMethod(project);
List<Pair<PsiExpression, PsiType>> arguments =
ContainerUtil.map2List(method.getParameterList().getParameters(), new Function<PsiParameter, Pair<PsiExpression, PsiType>>() {
public Pair<PsiExpression, PsiType> 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) {
@@ -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
@@ -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. <a href='bla-bla-bla'>[offset]. We want to extract
// only tag name then.
case ' ':
case '\t': endOffset = i;
}
}
return null;
@@ -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()) {
@@ -35,10 +35,8 @@ public class JavaClassTreeElement extends JavaClassTreeElementBase<PsiClass> {
}
private Collection<StructureViewTreeElement> getClassChildren() {
ArrayList<StructureViewTreeElement> array = new ArrayList<StructureViewTreeElement>();
final PsiClass aClass = getElement();
if (aClass == null) return array;
if (aClass == null) return Collections.emptyList();
List<PsiElement> children = Arrays.asList(aClass.getChildren());
Collection<PsiElement> ownChildren = new THashSet<PsiElement>();
@@ -47,6 +45,7 @@ public class JavaClassTreeElement extends JavaClassTreeElementBase<PsiClass> {
ContainerUtil.addAll(ownChildren, aClass.getInnerClasses());
ContainerUtil.addAll(ownChildren, aClass.getInitializers());
Collection<PsiElement> inherited = new LinkedHashSet<PsiElement>(children);
List<StructureViewTreeElement> array = new ArrayList<StructureViewTreeElement>(inherited.size());
aClass.processDeclarations(new AddAllMembersProcessor(inherited, aClass), ResolveState.initial(), null, aClass);
@@ -26,7 +26,6 @@ import java.util.ArrayList;
import java.util.Collection;
public class JavaFileTreeElement extends PsiTreeElementBase<PsiJavaFile> implements ItemPresentation {
public JavaFileTreeElement(PsiJavaFile file) {
super(file);
}
@@ -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);
}
@@ -37,6 +37,12 @@ public class JavadocTypedHandlerTest {
doTest("<t\nag><caret>", null);
}
@Test
public void tagWithAttribute() {
doTest("<a href='www'><caret>", "a");
//TODO den implement
}
private static void doTest(String text, String expected) {
StringBuilder normalized = new StringBuilder();
int offset = text.indexOf(CARET_MARKER);
@@ -42,4 +42,28 @@ class Test1 {
}
class FF<X> extends F<X>{}
class F<T> {}
class F<T> {}
class MyTest {
static class Foo<X> {
Foo(X x) {}
}
static interface Base<Y> {}
static class A extends Exception implements Base<String> {}
static class B extends Exception implements Base<Integer> {}
void m() throws B {
try {
if (true) {
throw new A();
}
else {
throw new B();
}
} catch (A ex) {
Foo<? extends Base<String>> foo1 = new Foo<>(ex); // ok
<error descr="Incompatible types. Found: 'MyTest.Foo<MyTest.A>', required: 'MyTest.Foo<MyTest.Base<java.lang.String>>'">Foo<Base<String>> foo2 = new Foo<>(ex);</error> // should be error
}
}
}
@@ -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() {
@@ -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);
}
}
@@ -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<? extends Object>\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<? extends Object>\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<? extends Object>\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<? extends Object>\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;
}
}
@@ -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<PomJavaChange> myChanges = new ArrayList<PomJavaChange>();
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<PomJavaChange> 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;
}
}
@@ -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;
}
}
@@ -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<Boolean>() {
public Boolean compute() {
if (!myIncludeTestSource && projectFileIndex.isInTestSourceContent(fileOrDir)) return false;
return ((GlobalSearchScope)myScope).contains(fileOrDir);
}
}).booleanValue();
@@ -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;
}
@@ -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);
}
@@ -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);
}
@@ -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) {
@@ -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<Object>() {
@Override
protected ChooseByNameFilter<Object> 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,
@@ -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 {
@@ -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<Object>() {
@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);
});
}
}
@@ -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<Class, String> ourLastStrings = new HashMap<Class, String>();
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<T> {
@Nullable
protected ChooseByNameFilter<T> 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 <T> void showNavigationPopup(AnActionEvent e, ChooseByNameModel model, final GotoActionCallback<T> 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<T> 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);
}
}
@@ -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<Language>() {
@Override
protected ChooseByNameFilter<Language> 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) {
@@ -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<FileType>() {
@Override
protected ChooseByNameFilter<FileType> 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<FileType> {
@@ -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<Language>() {
@Override
protected ChooseByNameFilter<Language> 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) {
@@ -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")
@@ -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<AbstractProjectViewPane> 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);
}
}
@@ -116,7 +116,7 @@ import java.util.List;
file = "$WORKSPACE_FILE$"
)}
)
public final class ProjectViewImpl extends ProjectView implements PersistentStateComponent<Element>, Disposable, QuickActionProvider {
public final class ProjectViewImpl extends ProjectView implements PersistentStateComponent<Element>, 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<JComponent>() {
@@ -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();
}
}
@@ -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) {
@@ -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();
@@ -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();
}
@@ -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<InlineHandler> handlers = InlineHandlers.getInlineHandlers(element.getLanguage());
for (InlineHandler handler : handlers) {
if (GenericInlineHandler.invoke(element, editor, handler)) {
@@ -102,8 +102,9 @@ public class FileBasedIndex implements ApplicationComponent {
private final Set<FileType> myNoLimitCheckTypes = new HashSet<FileType>();
private final PerIndexDocumentMap<Long> myLastIndexedDocStamps = new PerIndexDocumentMap<Long>() {
@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;
@@ -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<TreeUpdatePass> yielding = ui.getYeildingPasses();
for (Iterator<TreeUpdatePass> 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<TreeUpdatePass> 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;
}
@@ -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<Boolean> SHOW_CONTENT_ICON = new Key<Boolean>("ContentIcon");
@@ -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();
}
}
@@ -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);
}
@@ -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();
@@ -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();
}
}
@@ -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;
@@ -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) {
@@ -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) {
@@ -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<RangeHighlighterEx> list = new ArrayList<RangeHighlighterEx>();
int size = myHighlighterTree.size();
if (size == 0) return RangeHighlighter.EMPTY_ARRAY;
List<RangeHighlighterEx> list = new ArrayList<RangeHighlighterEx>(size);
myHighlighterTree.process(new CommonProcessors.CollectProcessor<RangeHighlighterEx>(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<RangeHighlighterEx> 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<RangeHighlighterEx> 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<RangeMarkerEx>() {
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<RangeHighlighterEx>() {
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();
}
}
@@ -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) { }
@@ -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<FinalizableCommand> cmd = new ArrayList<FinalizableCommand>();
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);
@@ -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<FinalizableCommand> commandList) {
public void execute(final ArrayList<FinalizableCommand> commandList) {
for (FinalizableCommand each : commandList) {
if (each.willChangeState()) {
fireStateChanged();
@@ -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<JComponent> 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;
}
@@ -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<DataProvider> myProviders = new ArrayList<DataProvider>();
@@ -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<String> 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<String> nodePrintCondition) {
private static void printImpl(JTree tree, Object root, StringBuilder buffer, int level, boolean withSelection, @Nullable Condition<String> 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
@@ -105,7 +105,10 @@ public class GroupNode extends Node implements Navigatable, Comparable<GroupNode
MergeableUsage mergeableUsage = (MergeableUsage)usage;
for (UsageNode node : myUsageNodes) {
Usage original = node.getUsage();
assert original != mergeableUsage : "Double add: " + usage +"; node: "+ node+"; already added: "+myUsageNodes;
if (original == mergeableUsage) {
// search returned duplicate usage, ignore
return node;
}
if (original instanceof MergeableUsage) {
if (((MergeableUsage)original).merge(mergeableUsage)) return node;
}
@@ -52,7 +52,7 @@ public class TransferToEDTQueue<T> {
T thing = myQueue.poll();
if (thing == null) break;
if (!myProcessor.process(thing)) {
myQueue.clear();
stop();
return;
}
processed++;
@@ -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;
@@ -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) {
}
}
}
@@ -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<Breadcrumb
final CaretListener caretListener = new CaretListener() {
public void caretPositionChanged(final CaretEvent e) {
if (myUserCaretChange) {
myQueue.cancelAllUpdates();
myQueue.queue(new MyUpdate(BreadcrumbsXmlWrapper.this, editor));
queueUpdate(editor);
}
myUserCaretChange = true;
@@ -118,19 +110,40 @@ public class BreadcrumbsXmlWrapper implements BreadcrumbsItemListener<Breadcrumb
}
});
PomManager.getModel(project).addModelListener(new PomModelListener() {
public void modelChanged(final PomModelEvent event) {
final PomChangeSet set = event.getChangeSet(event.getSource().getModelAspect(XmlAspect.class));
if (set instanceof XmlChangeSet && myQueue != null) {
myQueue.cancelAllUpdates();
myQueue.queue(new MyUpdate(BreadcrumbsXmlWrapper.this, editor));
}
PsiManager.getInstance(project).addPsiTreeChangeListener(new PsiTreeChangeAdapter() {
@Override
public void propertyChanged(PsiTreeChangeEvent event) {
PsiFile psiFile = event.getFile();
VirtualFile file = psiFile == null ? null : psiFile.getVirtualFile();
if (file != myFile) return;
queueUpdate(editor);
}
public boolean isAspectChangeInteresting(final PomModelAspect aspect) {
return aspect instanceof XmlAspect;
@Override
public void childrenChanged(PsiTreeChangeEvent event) {
propertyChanged(event);
}
}, this);
@Override
public void childMoved(PsiTreeChangeEvent event) {
propertyChanged(event);
}
@Override
public void childReplaced(PsiTreeChangeEvent event) {
propertyChanged(event);
}
@Override
public void childRemoved(PsiTreeChangeEvent event) {
propertyChanged(event);
}
@Override
public void childAdded(PsiTreeChangeEvent event) {
propertyChanged(event);
}
},this);
myComponent = new BreadcrumbsComponent<BreadcrumbsPsiItem>();
myComponent.addBreadcrumbsItemListener(this);
@@ -140,8 +153,7 @@ public class BreadcrumbsXmlWrapper implements BreadcrumbsItemListener<Breadcrumb
final ComponentAdapter resizeListener = new ComponentAdapter() {
public void componentResized(final ComponentEvent e) {
myQueue.cancelAllUpdates();
myQueue.queue(new MyUpdate(BreadcrumbsXmlWrapper.this, editor));
queueUpdate(editor);
}
};
@@ -166,6 +178,11 @@ public class BreadcrumbsXmlWrapper implements BreadcrumbsItemListener<Breadcrumb
myWrapperPanel.add(myComponent, BorderLayout.CENTER);
}
private void queueUpdate(Editor editor) {
myQueue.cancelAllUpdates();
myQueue.queue(new MyUpdate(this, editor));
}
private void moveEditorCaretTo(@NotNull final PsiElement element) {
if (element.isValid()) {
setUserCaretChange(false);