From 4d609d8448091285b53d48c41c313045e0aec4f7 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 26 Jan 2011 11:54:19 +0100 Subject: [PATCH 1/5] fix NPE on adding a library with invalid roots --- .../ui/configuration/libraryEditor/NewLibraryEditor.java | 4 ++++ .../src/com/intellij/openapi/roots/ui/LightFilePointer.java | 2 ++ 2 files changed, 6 insertions(+) diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/NewLibraryEditor.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/NewLibraryEditor.java index 412e21d0584b..7f74f68b1b0e 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/NewLibraryEditor.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/NewLibraryEditor.java @@ -81,6 +81,10 @@ public class NewLibraryEditor implements LibraryEditor { List result = new ArrayList(); for (LightFilePointer pointer : myRoots.get(rootType)) { final VirtualFile file = pointer.getFile(); + if (file == null) { + continue; + } + if (file.isDirectory()) { final Boolean recursively = myJarDirectories.get(file.getUrl()); if (recursively != null) { diff --git a/platform/platform-api/src/com/intellij/openapi/roots/ui/LightFilePointer.java b/platform/platform-api/src/com/intellij/openapi/roots/ui/LightFilePointer.java index a4315c359ade..74958b2b001f 100644 --- a/platform/platform-api/src/com/intellij/openapi/roots/ui/LightFilePointer.java +++ b/platform/platform-api/src/com/intellij/openapi/roots/ui/LightFilePointer.java @@ -19,6 +19,7 @@ import com.intellij.openapi.vfs.JarFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.File; @@ -35,6 +36,7 @@ public class LightFilePointer { myFile = file; } + @Nullable public VirtualFile getFile() { refreshFile(); return myFile; From 89029f4cb791f71c3cdddd9abc57ccc9f9ebf100 Mon Sep 17 00:00:00 2001 From: Anton Makeev Date: Tue, 25 Jan 2011 16:04:49 +0100 Subject: [PATCH 2/5] CIDR:Debugger: correctly inferring expression type + small OCType refactoring --- .../src/com/intellij/xdebugger/frame/XValueNode.java | 3 ++- .../intellij/xdebugger/impl/evaluate/quick/XValueHint.java | 5 +++++ .../xdebugger/impl/ui/tree/nodes/XValueNodeImpl.java | 4 ++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/platform/xdebugger-api/src/com/intellij/xdebugger/frame/XValueNode.java b/platform/xdebugger-api/src/com/intellij/xdebugger/frame/XValueNode.java index 600a4cdd078b..19bfc3a349da 100644 --- a/platform/xdebugger-api/src/com/intellij/xdebugger/frame/XValueNode.java +++ b/platform/xdebugger-api/src/com/intellij/xdebugger/frame/XValueNode.java @@ -30,11 +30,12 @@ import javax.swing.*; * @author nik */ public interface XValueNode extends Obsolescent { - void setPresentation(@Nullable Icon icon, @NonNls @Nullable String type, @NonNls @NotNull String value, boolean hasChildren); void setPresentation(@Nullable Icon icon, @NonNls @Nullable String type, @NonNls @NotNull String separator, @NonNls @NotNull String value, boolean hasChildren); + void errorOccurred(@NotNull String message, @Nullable String type); + /** * If string representation of the value is too long to show in the tree pass truncated value to {@link #setPresentation(javax.swing.Icon, String, String, boolean)} * method and call this method to provide full value. diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/evaluate/quick/XValueHint.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/evaluate/quick/XValueHint.java index 04f4ccb7274c..d0fdec5bf88d 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/evaluate/quick/XValueHint.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/evaluate/quick/XValueHint.java @@ -104,6 +104,11 @@ public class XValueHint extends AbstractValueHint { setPresentation(icon, type, separator, value, hasChildren); } + @Override + public void errorOccurred(@NotNull String message, @Nullable String type) { + setPresentation(XDebuggerUIConstants.ERROR_MESSAGE_ICON, type, message, false); + } + public void setFullValueEvaluator(@NotNull XFullValueEvaluator fullValueEvaluator) { //todo[nik] implement? } diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/nodes/XValueNodeImpl.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/nodes/XValueNodeImpl.java index 4b515c289095..f6ddcc60ab4b 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/nodes/XValueNodeImpl.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/nodes/XValueNodeImpl.java @@ -96,6 +96,10 @@ public class XValueNodeImpl extends XValueContainerNode implements XValu }); } + public void errorOccurred(@NotNull String message, @Nullable String type) { + setPresentation(XDebuggerUIConstants.ERROR_MESSAGE_ICON, type, message, false); + } + public void setFullValueEvaluator(@NotNull final XFullValueEvaluator fullValueEvaluator) { DebuggerUIUtil.invokeOnEventDispatch(new Runnable() { public void run() { From 604087db17cabb8e1a07ef1dd84806dcdb02a172 Mon Sep 17 00:00:00 2001 From: Anton Makeev Date: Wed, 26 Jan 2011 11:22:51 +0100 Subject: [PATCH 3/5] XDebugger: removed unused method --- .../src/com/intellij/xdebugger/frame/XValueNode.java | 2 -- .../intellij/xdebugger/impl/evaluate/quick/XValueHint.java | 5 ----- .../xdebugger/impl/ui/tree/nodes/XValueNodeImpl.java | 4 ---- 3 files changed, 11 deletions(-) diff --git a/platform/xdebugger-api/src/com/intellij/xdebugger/frame/XValueNode.java b/platform/xdebugger-api/src/com/intellij/xdebugger/frame/XValueNode.java index 19bfc3a349da..4c003c468754 100644 --- a/platform/xdebugger-api/src/com/intellij/xdebugger/frame/XValueNode.java +++ b/platform/xdebugger-api/src/com/intellij/xdebugger/frame/XValueNode.java @@ -34,8 +34,6 @@ public interface XValueNode extends Obsolescent { void setPresentation(@Nullable Icon icon, @NonNls @Nullable String type, @NonNls @NotNull String separator, @NonNls @NotNull String value, boolean hasChildren); - void errorOccurred(@NotNull String message, @Nullable String type); - /** * If string representation of the value is too long to show in the tree pass truncated value to {@link #setPresentation(javax.swing.Icon, String, String, boolean)} * method and call this method to provide full value. diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/evaluate/quick/XValueHint.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/evaluate/quick/XValueHint.java index d0fdec5bf88d..04f4ccb7274c 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/evaluate/quick/XValueHint.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/evaluate/quick/XValueHint.java @@ -104,11 +104,6 @@ public class XValueHint extends AbstractValueHint { setPresentation(icon, type, separator, value, hasChildren); } - @Override - public void errorOccurred(@NotNull String message, @Nullable String type) { - setPresentation(XDebuggerUIConstants.ERROR_MESSAGE_ICON, type, message, false); - } - public void setFullValueEvaluator(@NotNull XFullValueEvaluator fullValueEvaluator) { //todo[nik] implement? } diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/nodes/XValueNodeImpl.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/nodes/XValueNodeImpl.java index f6ddcc60ab4b..4b515c289095 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/nodes/XValueNodeImpl.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/nodes/XValueNodeImpl.java @@ -96,10 +96,6 @@ public class XValueNodeImpl extends XValueContainerNode implements XValu }); } - public void errorOccurred(@NotNull String message, @Nullable String type) { - setPresentation(XDebuggerUIConstants.ERROR_MESSAGE_ICON, type, message, false); - } - public void setFullValueEvaluator(@NotNull final XFullValueEvaluator fullValueEvaluator) { DebuggerUIUtil.invokeOnEventDispatch(new Runnable() { public void run() { From 16b28e606062016674023b5beef2199209b74612 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Wed, 26 Jan 2011 14:40:22 +0300 Subject: [PATCH 4/5] support for injected context --- .../src/com/intellij/psi/util/PsiFilter.java | 28 +++++++++++++++++ .../openapi/vcs/changes/PsiChangeTracker.java | 30 +++---------------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/platform/lang-api/src/com/intellij/psi/util/PsiFilter.java b/platform/lang-api/src/com/intellij/psi/util/PsiFilter.java index 3a8d5034f50d..0a6dec43eca6 100644 --- a/platform/lang-api/src/com/intellij/psi/util/PsiFilter.java +++ b/platform/lang-api/src/com/intellij/psi/util/PsiFilter.java @@ -17,8 +17,11 @@ package com.intellij.psi.util; import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiRecursiveElementVisitor; import org.jetbrains.annotations.NotNull; +import java.util.List; + /** * @author Konstantin Bulenkov */ @@ -41,4 +44,29 @@ public class PsiFilter { public boolean areEquivalent(T e1, T e2) { return e1.isEquivalentTo(e2); } + + public Visitor createVisitor(List elements) { + return new Visitor(this, elements); + } + + public static class Visitor extends PsiRecursiveElementVisitor { + private final PsiFilter filter; + private final List elements; + + protected Visitor(final PsiFilter filter, final List elements) { + this.filter = filter; + this.elements = elements; + } + + @Override + public void visitElement(PsiElement element) { + if (filter.getParentClass().isAssignableFrom(element.getClass())) { + final T e = (T)element; + if (filter.accept(e)) { + elements.add(e); + } + } + super.visitElement(element); + } + } } diff --git a/platform/lang-impl/src/com/intellij/openapi/vcs/changes/PsiChangeTracker.java b/platform/lang-impl/src/com/intellij/openapi/vcs/changes/PsiChangeTracker.java index 016c27062dbb..d8d0b5e6f85f 100644 --- a/platform/lang-impl/src/com/intellij/openapi/vcs/changes/PsiChangeTracker.java +++ b/platform/lang-impl/src/com/intellij/openapi/vcs/changes/PsiChangeTracker.java @@ -22,7 +22,6 @@ import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.fileEditor.impl.LoadTextUtil; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Computable; -import com.intellij.psi.util.PsiFilter; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.FileStatus; import com.intellij.openapi.vcs.FileStatusManager; @@ -31,7 +30,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiFileFactory; -import com.intellij.psi.PsiRecursiveElementVisitor; +import com.intellij.psi.util.PsiFilter; import org.jetbrains.annotations.Nullable; import java.util.*; @@ -64,14 +63,14 @@ public class PsiChangeTracker { final List elements = new ArrayList(); if (file == null) { - oldFile.accept(new MyVisitor(filter, oldElements)); + oldFile.accept(filter.createVisitor(oldElements)); calculateStatuses(elements, oldElements, result, filter); return result; } final Project project = file.getProject(); - file.accept(new MyVisitor(filter, elements)); + file.accept(filter.createVisitor(elements)); final VirtualFile vf = file.getVirtualFile(); FileStatus status = vf == null ? null : FileStatusManager.getInstance(project).getStatus(vf); if (status == null && oldFile == null) { @@ -88,7 +87,7 @@ public class PsiChangeTracker { } if (oldFile == null) return result; - oldFile.accept(new MyVisitor(filter, oldElements)); + oldFile.accept(filter.createVisitor(oldElements)); calculateStatuses(elements, oldElements, result, filter); return result; @@ -155,25 +154,4 @@ public class PsiChangeTracker { return null; } - - static class MyVisitor extends PsiRecursiveElementVisitor { - private final PsiFilter filter; - private final List elements; - - protected MyVisitor(final PsiFilter filter, final List elements) { - this.filter = filter; - this.elements = elements; - } - - @Override - public void visitElement(PsiElement element) { - if (filter.getParentClass().isAssignableFrom(element.getClass())) { - final T e = (T)element; - if (filter.accept(e)) { - elements.add(e); - } - } - super.visitElement(element); - } - } } From 50c144bb8276a8791de06d5e0678a2fc62c22dff Mon Sep 17 00:00:00 2001 From: Alexey Pegov Date: Wed, 26 Jan 2011 15:01:26 +0300 Subject: [PATCH 5/5] avoid dups --- .../intellij/notification/Notifications.java | 39 ++++++++----------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/platform/platform-api/src/com/intellij/notification/Notifications.java b/platform/platform-api/src/com/intellij/notification/Notifications.java index e056d4ee7f37..1b214dec7cb7 100644 --- a/platform/platform-api/src/com/intellij/notification/Notifications.java +++ b/platform/platform-api/src/com/intellij/notification/Notifications.java @@ -58,17 +58,8 @@ public interface Notifications { }); } else { - if (EventQueue.isDispatchThread()) { - project.getMessageBus().syncPublisher(TOPIC).notify(notification, defaultDisplayType); - } - else { - //noinspection SSBasedInspection - SwingUtilities.invokeLater(new Runnable() { - public void run() { - project.getMessageBus().syncPublisher(TOPIC).notify(notification, defaultDisplayType); - } - }); - } + final MessageBus bus = project.getMessageBus(); + _notify(notification, defaultDisplayType, bus); } return; @@ -80,20 +71,24 @@ public interface Notifications { final MessageBus bus = project == null ? ApplicationManager.getApplication().getMessageBus() : (project.isDisposed() ? null : project.getMessageBus()); if (bus != null) { - if (EventQueue.isDispatchThread()) { - bus.syncPublisher(TOPIC).notify(notification, defaultDisplayType); - } - else { - //noinspection SSBasedInspection - SwingUtilities.invokeLater(new Runnable() { - public void run() { - bus.syncPublisher(TOPIC).notify(notification, defaultDisplayType); - } - }); - } + _notify(notification, defaultDisplayType, bus); } } }); } + + private static void _notify(final Notification notification, final NotificationDisplayType defaultDisplayType, final MessageBus bus) { + if (EventQueue.isDispatchThread()) { + bus.syncPublisher(TOPIC).notify(notification, defaultDisplayType); + } + else { + //noinspection SSBasedInspection + SwingUtilities.invokeLater(new Runnable() { + public void run() { + bus.syncPublisher(TOPIC).notify(notification, defaultDisplayType); + } + }); + } + } } }