diff --git a/platform/platform-api/src/com/intellij/util/ui/ErrorTreeView.java b/platform/platform-api/src/com/intellij/util/ui/ErrorTreeView.java index f069ba016658..1870e7b4011b 100644 --- a/platform/platform-api/src/com/intellij/util/ui/ErrorTreeView.java +++ b/platform/platform-api/src/com/intellij/util/ui/ErrorTreeView.java @@ -19,6 +19,8 @@ import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.DataKey; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.pom.Navigatable; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; @@ -29,12 +31,35 @@ public interface ErrorTreeView extends Disposable { /** * If file is not null, allows to navigate to this file, line, column */ - void addMessage(int type, String[] text, VirtualFile file, int line, int column, Object data); + void addMessage(int type, + @NotNull String[] text, + @Nullable VirtualFile file, + int line, + int column, + @Nullable Object data); + + /** + * Allows adding messages related to other files under 'underFileGroup' + */ + void addMessage(int type, + @NotNull String[] text, + @Nullable VirtualFile underFileGroup, + @Nullable VirtualFile file, + int line, + int column, + @Nullable Object data); /** * add message, allowing navigation via custom Navigatable object */ - void addMessage(int type, String[] text, String groupName, Navigatable navigatable, String exportTextPrefix, String rendererTextPrefix, Object data); + void addMessage(int type, + @NotNull String[] text, + @NotNull String groupName, + @NotNull Navigatable navigatable, + @Nullable String exportTextPrefix, + @Nullable String rendererTextPrefix, + @Nullable Object data); + @NotNull JComponent getComponent(); } diff --git a/platform/platform-impl/src/com/intellij/ide/errorTreeView/ErrorViewStructure.java b/platform/platform-impl/src/com/intellij/ide/errorTreeView/ErrorViewStructure.java index 6336e78cd75e..3a2021a2071a 100644 --- a/platform/platform-impl/src/com/intellij/ide/errorTreeView/ErrorViewStructure.java +++ b/platform/platform-impl/src/com/intellij/ide/errorTreeView/ErrorViewStructure.java @@ -28,6 +28,7 @@ import com.intellij.ui.SimpleColoredComponent; import com.intellij.util.ArrayUtil; import com.intellij.util.ui.MutableErrorTreeView; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.util.*; @@ -142,20 +143,31 @@ public class ErrorViewStructure extends AbstractTreeStructure { return false; } - public void addMessage(ErrorTreeElementKind kind, String[] text, VirtualFile file, int line, int column, Object data) { - if (file != null) { + public void addMessage(ErrorTreeElementKind kind, + @NotNull String[] text, + @Nullable VirtualFile underFileGroup, + @Nullable VirtualFile file, + int line, + int column, + @Nullable Object data) { + if (underFileGroup != null || file != null) { + if (file == null) line = column = -1; + final int guiline = line < 0 ? -1 : line + 1; - final int guicolumn = column < 0 ? -1:column + 1; + final int guicolumn = column < 0 ? -1 : column + 1; + + VirtualFile group = underFileGroup != null ? underFileGroup : file; + VirtualFile nav = file != null ? file : underFileGroup; addNavigatableMessage( - file.getPresentableUrl(), - new OpenFileDescriptor(myProject, file, line, column), + group.getPresentableUrl(), + new OpenFileDescriptor(myProject, nav, line, column), kind, text, data, NewErrorTreeViewPanel.createExportPrefix(guiline), NewErrorTreeViewPanel.createRendererPrefix(guiline, guicolumn), - file + group ); } else { diff --git a/platform/platform-impl/src/com/intellij/ide/errorTreeView/NewErrorTreeViewPanel.java b/platform/platform-impl/src/com/intellij/ide/errorTreeView/NewErrorTreeViewPanel.java index e5f3eb16d4da..d91271637dde 100644 --- a/platform/platform-impl/src/com/intellij/ide/errorTreeView/NewErrorTreeViewPanel.java +++ b/platform/platform-impl/src/com/intellij/ide/errorTreeView/NewErrorTreeViewPanel.java @@ -38,6 +38,7 @@ import com.intellij.util.ui.MutableErrorTreeView; import com.intellij.util.ui.UIUtil; import com.intellij.util.ui.tree.TreeUtil; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; @@ -230,6 +231,7 @@ public class NewErrorTreeViewPanel extends JPanel implements DataProvider, Occur protected boolean shouldShowFirstErrorInEditor() { return false; } + public void clearMessages() { myErrorViewStructure.clear(); myBuilder.updateTree(); @@ -238,14 +240,36 @@ public class NewErrorTreeViewPanel extends JPanel implements DataProvider, Occur public void updateTree() { myBuilder.updateTree(); } - public void addMessage(int type, String[] text, VirtualFile file, int line, int column, Object data) { - myErrorViewStructure.addMessage(ErrorTreeElementKind.convertMessageFromCompilerErrorType(type), text, file, line, column, data); + + public void addMessage(int type, @NotNull String[] text, @Nullable VirtualFile file, int line, int column, @Nullable Object data) { + addMessage(type, text, null, file, line, column, data); + } + + @Override + public void addMessage(int type, + @NotNull String[] text, + @Nullable VirtualFile underFileGroup, + @Nullable VirtualFile file, + int line, + int column, + @Nullable Object data) { + myErrorViewStructure + .addMessage(ErrorTreeElementKind.convertMessageFromCompilerErrorType(type), text, underFileGroup, file, line, column, data); myBuilder.updateTree(); } - public void addMessage(int type, String[] text, String groupName, Navigatable navigatable, String exportTextPrefix, String rendererTextPrefix, Object data) { - myErrorViewStructure.addNavigatableMessage(groupName, navigatable, ErrorTreeElementKind.convertMessageFromCompilerErrorType(type), text, data, exportTextPrefix, rendererTextPrefix, - data instanceof VirtualFile ? (VirtualFile) data : null); + public void addMessage(int type, + @NotNull String[] text, + @NotNull String groupName, + @NotNull Navigatable navigatable, + @Nullable String exportTextPrefix, + @Nullable String rendererTextPrefix, + @Nullable Object data) { + myErrorViewStructure.addNavigatableMessage(groupName, navigatable, ErrorTreeElementKind.convertMessageFromCompilerErrorType(type), text, + data, + exportTextPrefix == null ? "" : exportTextPrefix, + rendererTextPrefix == null ? "" : rendererTextPrefix, + data instanceof VirtualFile ? (VirtualFile)data : null); myBuilder.updateTree(); } @@ -254,11 +278,13 @@ public class NewErrorTreeViewPanel extends JPanel implements DataProvider, Occur } public static String createExportPrefix(int line) { - return line < 0? "" : IdeBundle.message("errortree.prefix.line", line); + return line < 0 ? "" : IdeBundle.message("errortree.prefix.line", line); } public static String createRendererPrefix(int line, int column) { - return line < 0? "" : "(" + line + ", " + column + ")"; + if (line < 0) return ""; + if (column < 0) return "(" + line + ")"; + return "(" + line + ", " + column + ")"; } public JComponent getComponent() { @@ -267,7 +293,7 @@ public class NewErrorTreeViewPanel extends JPanel implements DataProvider, Occur private NavigatableMessageElement getSelectedMessageElement() { final ErrorTreeElement selectedElement = getSelectedErrorTreeElement(); - return selectedElement instanceof NavigatableMessageElement? (NavigatableMessageElement)selectedElement : null; + return selectedElement instanceof NavigatableMessageElement ? (NavigatableMessageElement)selectedElement : null; } public ErrorTreeElement getSelectedErrorTreeElement() { @@ -423,7 +449,7 @@ public class NewErrorTreeViewPanel extends JPanel implements DataProvider, Occur if (rerunAction != null) { leftUpdateableActionGroup.add(new RerunAction(rerunAction, closeMessageViewAction)); } - + leftUpdateableActionGroup.add(new StopAction()); if (myCreateExitAction) { leftUpdateableActionGroup.add(closeMessageViewAction); @@ -439,10 +465,10 @@ public class NewErrorTreeViewPanel extends JPanel implements DataProvider, Occur JPanel toolbarPanel = new JPanel(new GridLayout(1, 2)); final ActionManager actionManager = ActionManager.getInstance(); myLeftToolbar = - actionManager.createActionToolbar(ActionPlaces.COMPILER_MESSAGES_TOOLBAR, leftUpdateableActionGroup, false); + actionManager.createActionToolbar(ActionPlaces.COMPILER_MESSAGES_TOOLBAR, leftUpdateableActionGroup, false); toolbarPanel.add(myLeftToolbar.getComponent()); myRightToolbar = - actionManager.createActionToolbar(ActionPlaces.COMPILER_MESSAGES_TOOLBAR, rightUpdateableActionGroup, false); + actionManager.createActionToolbar(ActionPlaces.COMPILER_MESSAGES_TOOLBAR, rightUpdateableActionGroup, false); toolbarPanel.add(myRightToolbar.getComponent()); return toolbarPanel; @@ -521,7 +547,7 @@ public class NewErrorTreeViewPanel extends JPanel implements DataProvider, Occur } } - protected boolean canHideWarnings(){ + protected boolean canHideWarnings() { return true; } @@ -543,11 +569,11 @@ public class NewErrorTreeViewPanel extends JPanel implements DataProvider, Occur } } } - + public boolean isHideWarnings() { return ErrorTreeViewConfiguration.getInstance(myProject).isHideWarnings(); } - + private class MyTreeExpander implements TreeExpander { public void expandAll() { NewErrorTreeViewPanel.this.expandAll(); diff --git a/platform/util/src/com/intellij/openapi/util/text/StringUtil.java b/platform/util/src/com/intellij/openapi/util/text/StringUtil.java index 078c4ec16588..9836f79cf3c6 100644 --- a/platform/util/src/com/intellij/openapi/util/text/StringUtil.java +++ b/platform/util/src/com/intellij/openapi/util/text/StringUtil.java @@ -1313,6 +1313,10 @@ public class StringUtil { return range.replace(string, replacement); } + public static boolean startsWithWhitespace(@NotNull String text) { + return !text.isEmpty() && Character.isWhitespace(text.charAt(0)); + } + public static boolean startsWith(@NotNull CharSequence text, @NotNull CharSequence prefix) { int l1 = text.length(); int l2 = prefix.length();