From 13d594b165b0b764798fd981c91c5d0bc8107964 Mon Sep 17 00:00:00 2001 From: irengrig Date: Wed, 28 Nov 2012 18:33:09 +0400 Subject: [PATCH 1/8] IDEA-16710 Subversion: Limit "show history" revision count, additionally, [r=kirill.l] --- .../com/intellij/execution/process/ProcessHandler.java | 6 +++++- .../intellij/openapi/vcs/history/LimitHistoryCheck.java | 9 ++++----- .../history/VcsHistoryProviderBackgroundableProxy.java | 7 ++----- .../jetbrains/idea/svn/history/SvnHistoryProvider.java | 2 -- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/platform/util/src/com/intellij/execution/process/ProcessHandler.java b/platform/util/src/com/intellij/execution/process/ProcessHandler.java index f41e5b3ba79b..8ac34f2c1595 100644 --- a/platform/util/src/com/intellij/execution/process/ProcessHandler.java +++ b/platform/util/src/com/intellij/execution/process/ProcessHandler.java @@ -219,7 +219,11 @@ public abstract class ProcessHandler extends UserDataHolderBase { } private boolean isCanceledException(Throwable e) { - return e instanceof InvocationTargetException && e.getCause() instanceof ProcessCanceledException; + final boolean value = e instanceof InvocationTargetException && e.getCause() instanceof ProcessCanceledException; + if (value) { + LOG.info(e); + } + return value; } private final class TasksRunner extends ProcessAdapter { diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/LimitHistoryCheck.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/LimitHistoryCheck.java index 75261b3a94ba..64ed5686fd88 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/LimitHistoryCheck.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/LimitHistoryCheck.java @@ -51,11 +51,10 @@ public class LimitHistoryCheck { public void checkNumber() { if (myLimit <= 0) return; ++ myCnt; - if (myCnt >= myLimit) { + if (isOver()) { if (! myWarningShown) { - VcsBalloonProblemNotifier.showOverChangesView(myProject, "History loading for file " + myFilePath + - "\nwas interrupted. Only " + myLimit + " rows were loaded (allowed maximum).\n" + - "To change the history limit setting, go to Version Control settings.", MessageType.WARNING); + VcsBalloonProblemNotifier.showOverChangesView(myProject, "File History: only " + myLimit + " revisions were loaded for " + myFilePath + + "\nTo change the history limit, go to Settings | Version Control.", MessageType.WARNING); myWarningShown = true; } throw new ProcessCanceledException(); @@ -67,6 +66,6 @@ public class LimitHistoryCheck { } public boolean isOver() { - return myLimit > 0 && myLimit <= myCnt; + return myLimit > 0 && myLimit < myCnt; } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/VcsHistoryProviderBackgroundableProxy.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/VcsHistoryProviderBackgroundableProxy.java index 07f9fd0b2678..3940a38615dd 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/VcsHistoryProviderBackgroundableProxy.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/VcsHistoryProviderBackgroundableProxy.java @@ -140,13 +140,10 @@ public class VcsHistoryProviderBackgroundableProxy { if (full != null) { if (myConfiguration.LIMIT_HISTORY) { if (myConfiguration.MAXIMUM_HISTORY_ROWS < full.getRevisionList().size()) { - if (myConfiguration.MAXIMUM_HISTORY_ROWS < 2000) { - full = (VcsAbstractHistorySession) full.copy(); - } final List list = full.getRevisionList(); - final List part = new ArrayList(list.subList(0, myConfiguration.MAXIMUM_HISTORY_ROWS)); + final List was = new ArrayList(list.subList(0, myConfiguration.MAXIMUM_HISTORY_ROWS)); list.clear(); - list.addAll(part); + list.addAll(was); } } } diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/history/SvnHistoryProvider.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/history/SvnHistoryProvider.java index 437dff1aadfc..f695a0908d55 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/history/SvnHistoryProvider.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/history/SvnHistoryProvider.java @@ -21,7 +21,6 @@ import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.Ref; import com.intellij.openapi.vcs.FilePath; -import com.intellij.openapi.vcs.VcsConfiguration; import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vcs.annotate.ShowAllAffectedGenericAction; import com.intellij.openapi.vcs.changes.Change; @@ -505,7 +504,6 @@ public class SvnHistoryProvider final ThrowableConsumer result, SVNURL repoRootURL, Charset charset) throws SVNException, VcsException { - final VcsConfiguration configuration = VcsConfiguration.getInstance(vcs.getProject()); myVcs = vcs; myLastPathCorrector = new SvnPathThroughHistoryCorrection(lastPath); myCharset = charset; From f69dbece126fc215f428ef90e48330f60d85f227 Mon Sep 17 00:00:00 2001 From: "andrey.zaytsev" Date: Wed, 28 Nov 2012 18:56:57 +0400 Subject: [PATCH 2/8] IDEA-95582 Weird symbols in exceptions popup dialog --- .../ui/breakpoints/ExceptionBreakpointPropertiesPanel.java | 4 ++++ .../ui/breakpoints/FieldBreakpointPropertiesPanel.java | 3 +++ .../ui/breakpoints/MethodBreakpointPropertiesPanel.java | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/ExceptionBreakpointPropertiesPanel.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/ExceptionBreakpointPropertiesPanel.java index fbd11884c6f2..73680f50f495 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/ExceptionBreakpointPropertiesPanel.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/ExceptionBreakpointPropertiesPanel.java @@ -24,6 +24,7 @@ import com.intellij.debugger.DebuggerBundle; import com.intellij.ide.util.ClassFilter; import com.intellij.openapi.project.Project; import com.intellij.ui.IdeBorderFactory; +import com.intellij.util.ui.DialogUtil; import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -48,6 +49,9 @@ public class ExceptionBreakpointPropertiesPanel extends BreakpointPropertiesPane myNotifyCaughtCheckBox = new JCheckBox(DebuggerBundle.message("label.exception.breakpoint.properties.panel.caught.exception")); myNotifyUncaughtCheckBox = new JCheckBox(DebuggerBundle.message("label.exception.breakpoint.properties.panel.uncaught.exception")); + DialogUtil.registerMnemonic(myNotifyCaughtCheckBox); + DialogUtil.registerMnemonic(myNotifyUncaughtCheckBox); + Box notificationsBox = Box.createVerticalBox(); JPanel _panel = new JPanel(new BorderLayout()); diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/FieldBreakpointPropertiesPanel.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/FieldBreakpointPropertiesPanel.java index 81cf6a4d86ba..77497f7d7c5e 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/FieldBreakpointPropertiesPanel.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/FieldBreakpointPropertiesPanel.java @@ -23,6 +23,7 @@ package com.intellij.debugger.ui.breakpoints; import com.intellij.debugger.DebuggerBundle; import com.intellij.openapi.project.Project; import com.intellij.ui.IdeBorderFactory; +import com.intellij.util.ui.DialogUtil; import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -43,6 +44,8 @@ public class FieldBreakpointPropertiesPanel extends BreakpointPropertiesPanel { JPanel _panel0; myWatchAccessCheckBox = new JCheckBox(DebuggerBundle.message("label.filed.breakpoint.properties.panel.field.access")); myWatchModificationCheckBox = new JCheckBox(DebuggerBundle.message("label.filed.breakpoint.properties.panel.field.modification")); + DialogUtil.registerMnemonic(myWatchAccessCheckBox); + DialogUtil.registerMnemonic(myWatchModificationCheckBox); Box watchBox = Box.createVerticalBox(); diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/MethodBreakpointPropertiesPanel.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/MethodBreakpointPropertiesPanel.java index 3205dae7bb78..52984745d3fa 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/MethodBreakpointPropertiesPanel.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/MethodBreakpointPropertiesPanel.java @@ -23,6 +23,7 @@ package com.intellij.debugger.ui.breakpoints; import com.intellij.debugger.DebuggerBundle; import com.intellij.openapi.project.Project; import com.intellij.ui.IdeBorderFactory; +import com.intellij.util.ui.DialogUtil; import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -43,6 +44,9 @@ public class MethodBreakpointPropertiesPanel extends BreakpointPropertiesPanel { myWatchEntryCheckBox = new JCheckBox(DebuggerBundle.message("label.method.breakpoint.properties.panel.method.entry")); myWatchExitCheckBox = new JCheckBox(DebuggerBundle.message("label.method.breakpoint.properties.panel.method.exit")); + DialogUtil.registerMnemonic(myWatchEntryCheckBox); + DialogUtil.registerMnemonic(myWatchExitCheckBox); + Box watchBox = Box.createVerticalBox(); _panel = new JPanel(new BorderLayout()); From d145fc6227f8e484fe7591ff4ab70632a4436e17 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Wed, 28 Nov 2012 19:03:32 +0400 Subject: [PATCH 3/8] [git] assert -> LOG.assertTrue: we want this in log in release as well. Reviewed by irengrig --- plugins/git4idea/src/git4idea/GitRevisionNumber.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/git4idea/src/git4idea/GitRevisionNumber.java b/plugins/git4idea/src/git4idea/GitRevisionNumber.java index 3bf47f01fb81..fda5e3fa8e13 100644 --- a/plugins/git4idea/src/git4idea/GitRevisionNumber.java +++ b/plugins/git4idea/src/git4idea/GitRevisionNumber.java @@ -15,6 +15,7 @@ */ package git4idea; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.VcsException; @@ -47,6 +48,8 @@ public class GitRevisionNumber implements ShortVcsRevisionNumber { */ @NotNull private final Date myTimestamp; + private static final Logger LOG = Logger.getInstance(GitRevisionNumber.class); + /** * A constructor from version. The current date is used. * @@ -217,7 +220,7 @@ public class GitRevisionNumber implements ShortVcsRevisionNumber { @NotNull public static GitRevisionNumber parseRevlistOutputAsRevisionNumber(@NotNull GitSimpleHandler h, @NotNull String output) { StringTokenizer tokenizer = new StringTokenizer(output, "\n\r \t", false); - assert tokenizer.hasMoreTokens() : "No required tokens in the output: \n" + output; + LOG.assertTrue(tokenizer.hasMoreTokens(), "No required tokens in the output: \n" + output); Date timestamp = GitUtil.parseTimestampWithNFEReport(tokenizer.nextToken(), h, output); return new GitRevisionNumber(tokenizer.nextToken(), timestamp); } From d9a5768d3eaca5032cd569ab888a85d1cd2e8eb7 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 28 Nov 2012 16:36:35 +0400 Subject: [PATCH 4/8] cleanup --- .../ide/navigationToolbar/NavBarPanel.java | 26 +++-- .../openapi/editor/event/CaretEvent.java | 4 +- .../com/intellij/diagnostic/LogMessageEx.java | 3 +- .../openapi/editor/impl/CaretModelImpl.java | 97 ++++++++----------- 4 files changed, 61 insertions(+), 69 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPanel.java b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPanel.java index 143660181f5e..3244c947dbc7 100644 --- a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPanel.java +++ b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPanel.java @@ -37,7 +37,7 @@ import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.module.Module; -import com.intellij.openapi.module.ModuleUtil; +import com.intellij.openapi.module.ModuleUtilCore; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ui.configuration.actions.ModuleDeleteProvider; import com.intellij.openapi.ui.Queryable; @@ -47,7 +47,7 @@ import com.intellij.openapi.util.AsyncResult; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.vfs.VfsUtil; +import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.wm.IdeFocusManager; import com.intellij.openapi.wm.ToolWindowManager; @@ -105,7 +105,7 @@ public class NavBarPanel extends JPanel implements DataProvider, PopupOwner, Dis private boolean myDisposed = false; private RelativePoint myLocationCache; - public NavBarPanel(final Project project, boolean docked) { + public NavBarPanel(@NotNull Project project, boolean docked) { super(new FlowLayout(FlowLayout.LEFT, 0 , 0)); myProject = project; myModel = createModel(); @@ -119,6 +119,7 @@ public class NavBarPanel extends JPanel implements DataProvider, PopupOwner, Dis setBorder(new LineBorder(Gray._120, 1)); } myCopyPasteDelegator = new CopyPasteDelegator(myProject, NavBarPanel.this) { + @Override @NotNull protected PsiElement[] getSelectedElements() { final PsiElement element = getSelectedElement(PsiElement.class); @@ -251,10 +252,7 @@ public class NavBarPanel extends JPanel implements DataProvider, PopupOwner, Dis } boolean isSelectedInPopup(Object object) { - if (isNodePopupActive()) { - return Arrays.asList(myNodePopup.getSelectedValues()).contains(object); - } - return false; + return isNodePopupActive() && Arrays.asList(myNodePopup.getSelectedValues()).contains(object); } static Object optimizeTarget(Object target) { @@ -393,12 +391,14 @@ public class NavBarPanel extends JPanel implements DataProvider, PopupOwner, Dis //installDnD(index, component); ListenerUtil.addMouseListener(component, new MouseAdapter() { + @Override public void mouseReleased(final MouseEvent e) { if (SystemInfo.isWindows) { click(e); } } + @Override public void mousePressed(final MouseEvent e) { if (!SystemInfo.isWindows) { click(e); @@ -532,6 +532,7 @@ public class NavBarPanel extends JPanel implements DataProvider, PopupOwner, Dis myUpdateQueue.queueRebuildUi(); myUpdateQueue.queueAfterAll(new Runnable() { + @Override public void run() { int index = myModel.indexOf(obj); if (index >= 0) { @@ -587,6 +588,7 @@ public class NavBarPanel extends JPanel implements DataProvider, PopupOwner, Dis } } + @Override @Nullable public Object getData(String dataId) { if (PlatformDataKeys.PROJECT.is(dataId)) { @@ -597,7 +599,7 @@ public class NavBarPanel extends JPanel implements DataProvider, PopupOwner, Dis if (module != null && !module.isDisposed()) return module; final PsiElement element = getSelectedElement(PsiElement.class); if (element != null) { - return ModuleUtil.findModuleForPsiElement(element); + return ModuleUtilCore.findModuleForPsiElement(element); } return null; } @@ -606,7 +608,7 @@ public class NavBarPanel extends JPanel implements DataProvider, PopupOwner, Dis if (directory != null) { final VirtualFile dir = directory.getVirtualFile(); if (ProjectRootsUtil.isModuleContentRoot(dir, myProject)) { - return ModuleUtil.findModuleForPsiElement(directory); + return ModuleUtilCore.findModuleForPsiElement(directory); } } return null; @@ -642,7 +644,7 @@ public class NavBarPanel extends JPanel implements DataProvider, PopupOwner, Dis files.add(((PsiFileSystemItem)element).getVirtualFile()); } } - return files.size() > 0 ? VfsUtil.toVirtualFileArray(files) : null; + return !files.isEmpty() ? VfsUtilCore.toVirtualFileArray(files) : null; } if (PlatformDataKeys.NAVIGATABLE_ARRAY.is(dataId)) { @@ -712,6 +714,7 @@ public class NavBarPanel extends JPanel implements DataProvider, PopupOwner, Dis } + @Override public Point getBestPopupPosition() { int index = myModel.getSelectedIndex(); final int modelSize = myModel.size(); @@ -727,11 +730,13 @@ public class NavBarPanel extends JPanel implements DataProvider, PopupOwner, Dis return null; } + @Override public void addNotify() { super.addNotify(); NavBarListener.subscribeTo(this); } + @Override public void removeNotify() { super.removeNotify(); Disposer.dispose(this); @@ -754,6 +759,7 @@ public class NavBarPanel extends JPanel implements DataProvider, PopupOwner, Dis panel.setBackground(UIUtil.isUnderGTKLookAndFeel() ? Color.WHITE : UIUtil.getListBackground()); myHint = new LightweightHint(panel) { + @Override public void hide() { super.hide(); cancelPopup(); diff --git a/platform/platform-api/src/com/intellij/openapi/editor/event/CaretEvent.java b/platform/platform-api/src/com/intellij/openapi/editor/event/CaretEvent.java index 32855fd848ec..4f491287cfa4 100644 --- a/platform/platform-api/src/com/intellij/openapi/editor/event/CaretEvent.java +++ b/platform/platform-api/src/com/intellij/openapi/editor/event/CaretEvent.java @@ -25,7 +25,7 @@ public class CaretEvent extends EventObject { private final LogicalPosition myOldPosition; private final LogicalPosition myNewPosition; - public CaretEvent(@NotNull Editor editor, LogicalPosition oldPosition, LogicalPosition newPosition) { + public CaretEvent(@NotNull Editor editor, @NotNull LogicalPosition oldPosition, @NotNull LogicalPosition newPosition) { super(editor); myOldPosition = oldPosition; myNewPosition = newPosition; @@ -36,10 +36,12 @@ public class CaretEvent extends EventObject { return (Editor) getSource(); } + @NotNull public LogicalPosition getOldPosition() { return myOldPosition; } + @NotNull public LogicalPosition getNewPosition() { return myNewPosition; } diff --git a/platform/platform-impl/src/com/intellij/diagnostic/LogMessageEx.java b/platform/platform-impl/src/com/intellij/diagnostic/LogMessageEx.java index 852389318bbd..a47d919743de 100644 --- a/platform/platform-impl/src/com/intellij/diagnostic/LogMessageEx.java +++ b/platform/platform-impl/src/com/intellij/diagnostic/LogMessageEx.java @@ -20,6 +20,7 @@ import com.intellij.openapi.diagnostic.IdeaLoggingEvent; import com.intellij.openapi.diagnostic.Logger; import com.intellij.util.ExceptionUtil; import com.intellij.util.SmartList; +import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -132,7 +133,7 @@ public class LogMessageEx extends LogMessage { }; } - public static void error(@NotNull Logger logger, @NotNull String message, @NotNull String... attachmentText) { + public static void error(@NotNull Logger logger, @NonNls @NotNull String message, @NotNull String... attachmentText) { error(logger, message, new Throwable(), attachmentText); } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java index 56ab89e53431..13da24ce6094 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java @@ -43,9 +43,10 @@ import com.intellij.openapi.editor.impl.event.DocumentEventImpl; import com.intellij.openapi.editor.impl.softwrap.SoftWrapHelper; import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.util.containers.ContainerUtil; +import com.intellij.util.EventDispatcher; import com.intellij.util.diff.FilesTooBigForDiffException; import com.intellij.util.text.CharArrayUtil; +import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -53,12 +54,10 @@ import java.awt.*; import java.util.List; public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener, Disposable { - private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.editor.impl.CaretModelImpl"); - + private final EditorImpl myEditor; - private final List myCaretListeners = ContainerUtil.createEmptyCOWList(); - + private final EventDispatcher myCaretListeners = EventDispatcher.create(CaretListener.class); private LogicalPosition myLogicalCaret; private VerticalInfo myCaretInfo; private VisualPosition myVisibleCaret; @@ -114,6 +113,7 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener, if (doc != myEditor.getDocument() || myOffset >= doc.getTextLength() || savedBeforeBulkCaretMarker != null) return; savedBeforeBulkCaretMarker = doc.createRangeMarker(myOffset, myOffset); } + @Override public void updateFinished(@NotNull Document doc) { if (doc != myEditor.getDocument() || myIsInUpdate) return; @@ -193,12 +193,9 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener, myEditor.updateCaretCursor(); requestRepaint(oldInfo); - if (oldPosition.column != myLogicalCaret.column || oldPosition.line != myLogicalCaret.line) { + if (!oldPosition.equals(myLogicalCaret)) { CaretEvent event = new CaretEvent(myEditor, oldPosition, myLogicalCaret); - - for (CaretListener listener : myCaretListeners) { - listener.caretPositionChanged(event); - } + myCaretListeners.getMulticaster().caretPositionChanged(event); } } @@ -219,11 +216,11 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener, return; } final LogicalPosition logicalPosition = myEditor.offsetToLogicalPosition(offset); - final CaretEvent event = moveToLogicalPosition(logicalPosition, locateBeforeSoftWrap, null, true); + CaretEvent event = moveToLogicalPosition(logicalPosition, locateBeforeSoftWrap, null, false); final LogicalPosition positionByOffsetAfterMove = myEditor.offsetToLogicalPosition(myOffset); if (!myIgnoreWrongMoves && !positionByOffsetAfterMove.equals(logicalPosition)) { StringBuilder debugBuffer = new StringBuilder(); - moveToLogicalPosition(logicalPosition, locateBeforeSoftWrap, debugBuffer, false); + moveToLogicalPosition(logicalPosition, locateBeforeSoftWrap, debugBuffer, true); int textStart = Math.max(0, Math.min(offset, myOffset) - 1); final DocumentEx document = myEditor.getDocument(); int textEnd = Math.min(document.getTextLength() - 1, Math.max(offset, myOffset) + 1); @@ -237,12 +234,10 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener, + "interested text [%d;%d): '%s'%n debug trace: %s%nLogical position -> offset ('%s'->'%d') trace: %s", offset, logicalPosition, myOffset, myLogicalCaret, positionByOffsetAfterMove, myEditor.dumpState(), textStart, textEnd, text, debugBuffer, logicalPosition, inverseOffset, positionToOffsetTrace - )); + )); } if (event != null) { - for (CaretListener listener : myCaretListeners) { - listener.caretPositionChanged(event); - } + myCaretListeners.getMulticaster().caretPositionChanged(event); EditorActionUtil.selectNonexpandableFold(myEditor); } } @@ -256,8 +251,7 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener, int lineShift, boolean withSelection, boolean blockSelection, - boolean scrollToCaret) - { + boolean scrollToCaret) { assertIsDispatchThread(); if (mySkipChangeRequests) { return; @@ -399,7 +393,7 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener, if (scrollToCaret) { myEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); } - + if (desiredX >= 0) { myDesiredX = desiredX; } @@ -409,14 +403,14 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener, @Override public void moveToLogicalPosition(@NotNull LogicalPosition pos) { - moveToLogicalPosition(pos, false, null, false); + moveToLogicalPosition(pos, false, null, true); } @Nullable private CaretEvent moveToLogicalPosition(@NotNull LogicalPosition pos, boolean locateBeforeSoftWrap, @Nullable StringBuilder debugBuffer, - boolean delayListenersNotification) { + boolean fireListeners) { if (mySkipChangeRequests) { return null; } @@ -425,7 +419,7 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener, } myReportCaretMoves = true; try { - return doMoveToLogicalPosition(pos, locateBeforeSoftWrap, debugBuffer, delayListenersNotification); + return doMoveToLogicalPosition(pos, locateBeforeSoftWrap, debugBuffer, fireListeners); } finally { myReportCaretMoves = false; @@ -434,14 +428,11 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener, private CaretEvent doMoveToLogicalPosition(@NotNull LogicalPosition pos, boolean locateBeforeSoftWrap, - @Nullable StringBuilder debugBuffer, - boolean delayListenersNotification) - { + @NonNls @Nullable StringBuilder debugBuffer, + boolean fireListeners) { assertIsDispatchThread(); if (debugBuffer != null) { - debugBuffer.append(String.format( - "Start moveToLogicalPosition(). Locate before soft wrap: %b, position: %s%n", locateBeforeSoftWrap, pos - )); + debugBuffer.append("Start moveToLogicalPosition(). Locate before soft wrap: " + locateBeforeSoftWrap + ", position: " + pos + "\n"); } myDesiredX = -1; validateCallContext(); @@ -478,9 +469,7 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener, } else if (line > lineCount - 1) { if (debugBuffer != null) { - debugBuffer.append(String.format( - "Resetting target logical line (%d) to %d as it is greater than total document lines number%n", line, lineCount - 1 - )); + debugBuffer.append("Resetting target logical line (" + line + ") to " + (lineCount - 1) + " as it is greater than total document lines number\n"); } line = lineCount - 1; softWrapLinesBefore = 0; @@ -500,11 +489,10 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener, softWrapColumns -= column - lineEndColumnNumber; } if (debugBuffer != null) { - debugBuffer.append(String.format( - "Resetting target logical column (%d) to %d because caret is not allowed to be located after line end (offset: %d, " - + "logical position: %s). Current soft wrap columns value: %d%n", - oldColumn, lineEndColumnNumber, lineEndOffset, endLinePosition, softWrapColumns - )); + debugBuffer.append( + "Resetting target logical column (" + oldColumn + ") to " + lineEndColumnNumber + + " because caret is not allowed to be located after line end (offset: " +lineEndOffset + ", " + + "logical position: " + endLinePosition+ "). Current soft wrap columns value: " + softWrapColumns+ "\n"); } } } @@ -526,7 +514,8 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener, setCurrentLogicalCaret(logicalPositionToUse); final int offset = myEditor.logicalPositionToOffset(myLogicalCaret); if (debugBuffer != null) { - debugBuffer.append(String.format("Resulting logical position to use: %s. It's mapped to offset %d%n", myLogicalCaret, offset)); + debugBuffer.append("Resulting logical position to use: " + myLogicalCaret+ + ". It's mapped to offset " + offset+ "\n"); } FoldRegion collapsedAt = myEditor.getFoldingModel().getCollapsedRegionAtOffset(offset); @@ -559,7 +548,7 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener, myOffset = myEditor.logicalPositionToOffset(myLogicalCaret); if (debugBuffer != null) { - debugBuffer.append(String.format("Storing offset %d (mapped from logical position %s)%n", myOffset, myLogicalCaret)); + debugBuffer.append("Storing offset " + myOffset + " (mapped from logical position " + myLogicalCaret + ")\n"); } LOG.assertTrue(myOffset >= 0 && myOffset <= myEditor.getDocument().getTextLength()); @@ -574,9 +563,7 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener, if (lineToUse >= 0) { final VisualPosition visualPosition = new VisualPosition(lineToUse, EditorUtil.getLastVisualLineColumnNumber(myEditor, lineToUse)); if (debugBuffer != null) { - debugBuffer.append(String.format( - "Adjusting caret position by moving it before soft wrap. Moving to visual position %s%n", visualPosition - )); + debugBuffer.append("Adjusting caret position by moving it before soft wrap. Moving to visual position "+ visualPosition+"\n"); } final LogicalPosition logicalPosition = myEditor.visualToLogicalPosition(visualPosition); final int tmpOffset = myEditor.logicalPositionToOffset(logicalPosition); @@ -597,19 +584,16 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener, + "State: %s", visualPosition, myOffset, logicalPosition, tmpOffset, myEditor.dumpState() )); } - } } if (!oldCaretPosition.toVisualPosition().equals(myLogicalCaret.toVisualPosition())) { CaretEvent event = new CaretEvent(myEditor, oldCaretPosition, myLogicalCaret); - if (delayListenersNotification) { - return event; + if (fireListeners) { + myCaretListeners.getMulticaster().caretPositionChanged(event); } else { - for (CaretListener listener : myCaretListeners) { - listener.caretPositionChanged(event); - } + return event; } } return null; @@ -677,13 +661,12 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener, @Override public void addCaretListener(@NotNull CaretListener listener) { - myCaretListeners.add(listener); + myCaretListeners.addListener(listener); } @Override public void removeCaretListener(@NotNull CaretListener listener) { - boolean success = myCaretListeners.remove(listener); - LOG.assertTrue(success); + myCaretListeners.removeListener(listener); } @Override @@ -707,9 +690,9 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener, DocumentEventImpl event = (DocumentEventImpl)e; final DocumentEx document = myEditor.getDocument(); boolean performSoftWrapAdjustment = e.getNewLength() > 0 // We want to put caret just after the last added symbol - // There is a possible case that the user removes text just before the soft wrap. We want to keep caret - // on a visual line with soft wrap start then. - || myEditor.getSoftWrapModel().getSoftWrap(e.getOffset()) != null; + // There is a possible case that the user removes text just before the soft wrap. We want to keep caret + // on a visual line with soft wrap start then. + || myEditor.getSoftWrapModel().getSoftWrap(e.getOffset()) != null; if (event.isWholeTextReplaced()) { int newLength = document.getTextLength(); @@ -719,7 +702,7 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener, else { try { final int line = event.translateLineViaDiff(myLogicalCaret.line); - moveToLogicalPosition(new LogicalPosition(line, myLogicalCaret.column), performSoftWrapAdjustment, null, false); + moveToLogicalPosition(new LogicalPosition(line, myLogicalCaret.column), performSoftWrapAdjustment, null, true); } catch (FilesTooBigForDiffException e1) { LOG.info(e1); @@ -744,7 +727,7 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener, newOffset = Math.min(newOffset, document.getTextLength()); // if (newOffset != myOffset) { - moveToOffset(newOffset, performSoftWrapAdjustment); + moveToOffset(newOffset, performSoftWrapAdjustment); //} //else { // moveToVisualPosition(oldPosition); @@ -760,9 +743,9 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener, } private boolean needToShiftWhiteSpaces(final DocumentEvent e) { - if(!CharArrayUtil.containsOnlyWhiteSpaces(e.getNewFragment()) || CharArrayUtil.containLineBreaks(e.getNewFragment())) + if (!CharArrayUtil.containsOnlyWhiteSpaces(e.getNewFragment()) || CharArrayUtil.containLineBreaks(e.getNewFragment())) return e.getOldLength() > 0; - if(e.getOffset() == 0) return false; + if (e.getOffset() == 0) return false; final char charBefore = myEditor.getDocument().getCharsSequence().charAt(e.getOffset() - 1); //final char charAfter = myEditor.getDocument().getCharsSequence().charAt(e.getOffset() + e.getNewLength()); return Character.isWhitespace(charBefore)/* || !Character.isWhitespace(charAfter)*/; From 9299ca2491231bb47acf14ff3adb881fac82fb1b Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 28 Nov 2012 17:50:03 +0400 Subject: [PATCH 5/8] IDEA-95452 -1: -1 java.lang.AssertionError: -1 --- .../src/com/intellij/openapi/editor/impl/EditorImpl.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java index 125f5f806e2f..86a2d2b81b60 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java @@ -3262,10 +3262,11 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi int lineHeight = myLineHeight; if (lineHeight == -1) { FontMetrics fontMetrics = myEditorComponent.getFontMetrics(myScheme.getFont(EditorFontType.PLAIN)); - lineHeight = (int)(fontMetrics.getHeight() * (isOneLineMode() ? 1 : myScheme.getLineSpacing())); - if (lineHeight == 0) { - lineHeight = fontMetrics.getHeight(); - if (lineHeight == 0) { + int fontMetricsHeight = fontMetrics.getHeight(); + lineHeight = (int)(fontMetricsHeight * (isOneLineMode() ? 1 : myScheme.getLineSpacing())); + if (lineHeight <= 0) { + lineHeight = fontMetricsHeight; + if (lineHeight <= 0) { lineHeight = 12; } } From 8163c24e22aa348b01d674493b6e3f247f3a5fe0 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 28 Nov 2012 17:50:34 +0400 Subject: [PATCH 6/8] http://ea.jetbrains.com/browser/ea_reports/426772 (r:Denis Zhdanov) --- .../com/intellij/usages/UsageInfo2UsageAdapter.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/platform/usageView/src/com/intellij/usages/UsageInfo2UsageAdapter.java b/platform/usageView/src/com/intellij/usages/UsageInfo2UsageAdapter.java index d68eb158c31b..daa4c67b6ce5 100644 --- a/platform/usageView/src/com/intellij/usages/UsageInfo2UsageAdapter.java +++ b/platform/usageView/src/com/intellij/usages/UsageInfo2UsageAdapter.java @@ -99,9 +99,15 @@ public class UsageInfo2UsageAdapter implements UsageInModule, lineNumber = -1; } else { - offset = -1; int startOffset = myUsageInfo.getNavigationOffset(); - lineNumber = getLineNumber(document, startOffset); + if (startOffset == -1) { + offset = element == null ? 0 : element.getTextOffset(); + lineNumber = -1; + } + else { + offset = -1; + lineNumber = getLineNumber(document, startOffset); + } } return Pair.create(offset, lineNumber); } From 5ac61a1eab591b8033fd01d89b9862fb41a5a00a Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 28 Nov 2012 19:00:15 +0400 Subject: [PATCH 7/8] assertion for default project --- .../openapi/roots/impl/LanguageLevelProjectExtensionImpl.java | 2 +- .../src/com/intellij/openapi/roots/impl/DirectoryIndex.java | 1 + .../src/org/jetbrains/android/dom/AndroidXmlExtension.java | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/java/java-impl/src/com/intellij/openapi/roots/impl/LanguageLevelProjectExtensionImpl.java b/java/java-impl/src/com/intellij/openapi/roots/impl/LanguageLevelProjectExtensionImpl.java index cfd08bb95841..dd5252be8905 100644 --- a/java/java-impl/src/com/intellij/openapi/roots/impl/LanguageLevelProjectExtensionImpl.java +++ b/java/java-impl/src/com/intellij/openapi/roots/impl/LanguageLevelProjectExtensionImpl.java @@ -101,7 +101,7 @@ public class LanguageLevelProjectExtensionImpl extends LanguageLevelProjectExten } myLanguageLevel = languageLevel; - if (!willReload() && DirectoryIndex.getInstance(myProject).isInitialized()) { + if (!willReload() && !myProject.isDefault() && DirectoryIndex.getInstance(myProject).isInitialized()) { JavaLanguageLevelPusher.pushLanguageLevel(myProject); } } diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/DirectoryIndex.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/DirectoryIndex.java index dd4318de8937..953cf2d57474 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/DirectoryIndex.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/DirectoryIndex.java @@ -26,6 +26,7 @@ import org.jetbrains.annotations.TestOnly; public abstract class DirectoryIndex { public static DirectoryIndex getInstance(Project project) { + assert !project.isDefault() : "Must not call DirectoryIndex for default project"; return ServiceManager.getService(project, DirectoryIndex.class); } diff --git a/plugins/android/src/org/jetbrains/android/dom/AndroidXmlExtension.java b/plugins/android/src/org/jetbrains/android/dom/AndroidXmlExtension.java index f9a2a537017c..33ee5d0d772b 100644 --- a/plugins/android/src/org/jetbrains/android/dom/AndroidXmlExtension.java +++ b/plugins/android/src/org/jetbrains/android/dom/AndroidXmlExtension.java @@ -17,6 +17,7 @@ package org.jetbrains.android.dom; import com.intellij.lang.ASTNode; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.impl.DirectoryIndex; import com.intellij.openapi.util.Computable; import com.intellij.psi.PsiFile; @@ -43,7 +44,8 @@ public class AndroidXmlExtension extends DefaultXmlExtension { @Override public boolean isAvailable(final PsiFile file) { if (file instanceof XmlFile) { - if (!DirectoryIndex.getInstance(file.getProject()).isInitialized()) { + Project project = file.getProject(); + if (!project.isDefault() && !DirectoryIndex.getInstance(project).isInitialized()) { return false; } From 9abd12c3190cfb3dfa5c7df633c098f39fce9fed Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 28 Nov 2012 19:02:29 +0400 Subject: [PATCH 8/8] cache unsuccessful parses --- .../BaseExternalAnnotationsManager.java | 112 ++++++++---------- 1 file changed, 52 insertions(+), 60 deletions(-) diff --git a/java/java-indexing-impl/src/com/intellij/codeInsight/BaseExternalAnnotationsManager.java b/java/java-indexing-impl/src/com/intellij/codeInsight/BaseExternalAnnotationsManager.java index 2284de42ff49..89638cdb67ae 100644 --- a/java/java-indexing-impl/src/com/intellij/codeInsight/BaseExternalAnnotationsManager.java +++ b/java/java-indexing-impl/src/com/intellij/codeInsight/BaseExternalAnnotationsManager.java @@ -30,7 +30,6 @@ import com.intellij.psi.util.PsiFormatUtil; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.ConcurrencyUtil; import com.intellij.util.IncorrectOperationException; -import com.intellij.util.StringBuilderSpinAllocator; import com.intellij.util.ThreeState; import com.intellij.util.containers.ConcurrentSoftHashMap; import com.intellij.util.containers.ConcurrentSoftValueHashMap; @@ -72,33 +71,28 @@ public class BaseExternalAnnotationsManager extends ExternalAnnotationsManager { @Nullable protected static String getNormalizedExternalName(@NotNull PsiModifierListOwner owner) { String externalName = getExternalName(owner, true); - if (externalName != null) { - if (owner instanceof PsiParameter && owner.getParent() instanceof PsiParameterList) { - final PsiMethod method = PsiTreeUtil.getParentOfType(owner, PsiMethod.class); - if (method != null) { - externalName = - externalName.substring(0, externalName.lastIndexOf(' ') + 1) + method.getParameterList().getParameterIndex((PsiParameter)owner); - } - } - final int idx = externalName.indexOf('('); - if (idx == -1) return externalName; - final StringBuilder buf = StringBuilderSpinAllocator.alloc(); - try { - final int rightIdx = externalName.indexOf(')'); - final String[] params = externalName.substring(idx + 1, rightIdx).split(","); - buf.append(externalName.substring(0, idx + 1)); - for (String param : params) { - param = param.trim(); - final int spaceIdx = param.indexOf(' '); - buf.append(spaceIdx > -1 ? param.substring(0, spaceIdx) : param).append(", "); - } - return StringUtil.trimEnd(buf.toString(), ", ") + externalName.substring(rightIdx); - } - finally { - StringBuilderSpinAllocator.dispose(buf); + if (externalName == null) { + return null; + } + if (owner instanceof PsiParameter && owner.getParent() instanceof PsiParameterList) { + final PsiMethod method = PsiTreeUtil.getParentOfType(owner, PsiMethod.class); + if (method != null) { + externalName = + externalName.substring(0, externalName.lastIndexOf(' ') + 1) + method.getParameterList().getParameterIndex((PsiParameter)owner); } } - return externalName; + final int idx = externalName.indexOf('('); + if (idx == -1) return externalName; + StringBuilder buf = new StringBuilder(); + int rightIdx = externalName.indexOf(')'); + String[] params = externalName.substring(idx + 1, rightIdx).split(","); + buf.append(externalName.substring(0, idx + 1)); + for (String param : params) { + param = param.trim(); + final int spaceIdx = param.indexOf(' '); + buf.append(spaceIdx > -1 ? param.substring(0, spaceIdx) : param).append(", "); + } + return StringUtil.trimEnd(buf.toString(), ", ") + externalName.substring(rightIdx); } protected boolean hasAnyAnnotationsRoots() { @@ -151,56 +145,54 @@ public class BaseExternalAnnotationsManager extends ExternalAnnotationsManager { return map; } - private static final MultiMap EMPTY = new MultiMap(); - private ConcurrentMap, Long>> annotationsFileToDataAndModificationStamp = new ConcurrentSoftHashMap, Long>>(); + private final ConcurrentMap, Long>> annotationsFileToDataAndModificationStamp = new ConcurrentSoftHashMap, Long>>(); @NotNull private MultiMap getDataFromFile(@NotNull PsiFile file) { Pair, Long> cached = annotationsFileToDataAndModificationStamp.get(file); if (cached != null && cached.getSecond() == file.getModificationStamp()) { return cached.getFirst(); } - Document document; + MultiMap data = new MultiMap(); try { VirtualFile virtualFile = file.getVirtualFile(); - if (virtualFile == null) return EMPTY; - document = JDOMUtil.loadDocument(escapeAttributes(StreamUtil.readText(virtualFile.getInputStream()))); + if (virtualFile != null) { + Document document = JDOMUtil.loadDocument(escapeAttributes(StreamUtil.readText(virtualFile.getInputStream()))); + Element rootElement = document.getRootElement(); + if (rootElement != null) { + //noinspection unchecked + for (Element element : (List) rootElement.getChildren()) { + String ownerName = element.getAttributeValue("name"); + if (ownerName == null) continue; + //noinspection unchecked + for (Element annotationElement : (List) element.getChildren()) { + String annotationFQN = annotationElement.getAttributeValue("name"); + if (StringUtil.isEmpty(annotationFQN)) continue; + StringBuilder buf = new StringBuilder(); + //noinspection unchecked + for (Element annotationParameter : (List) annotationElement.getChildren()) { + buf.append(","); + String nameValue = annotationParameter.getAttributeValue("name"); + if (nameValue != null) { + buf.append(nameValue).append("="); + } + buf.append(annotationParameter.getAttributeValue("val")); + } + String annotationText = "@" + annotationFQN + (buf.length() > 0 ? "(" + StringUtil.trimStart(buf.toString(), ",") + ")" : ""); + data.putValue(ownerName, new AnnotationData(annotationFQN, annotationText)); + } + } + } + } } catch (IOException e) { LOG.error(e); - return EMPTY; } catch (JDOMException e) { LOG.error(e); - return EMPTY; } - Element rootElement = document.getRootElement(); - if (rootElement == null) return EMPTY; - - MultiMap data = new MultiMap(); - - //noinspection unchecked - for (Element element : (List) rootElement.getChildren()) { - String ownerName = element.getAttributeValue("name"); - if (ownerName == null) continue; - //noinspection unchecked - for (Element annotationElement : (List) element.getChildren()) { - String annotationFQN = annotationElement.getAttributeValue("name"); - if (StringUtil.isEmpty(annotationFQN)) continue; - StringBuilder buf = new StringBuilder(); - //noinspection unchecked - for (Element annotationParameter : (List) annotationElement.getChildren()) { - buf.append(","); - String nameValue = annotationParameter.getAttributeValue("name"); - if (nameValue != null) { - buf.append(nameValue).append("="); - } - buf.append(annotationParameter.getAttributeValue("val")); - } - String annotationText = "@" + annotationFQN + (buf.length() > 0 ? "(" + StringUtil.trimStart(buf.toString(), ",") + ")" : ""); - data.putValue(ownerName, new AnnotationData(annotationFQN, annotationText)); - } + if (data.isEmpty()) { + data = MultiMap.emptyInstance(); } - Pair, Long> pair = Pair.create(data, file.getModificationStamp()); pair = ConcurrencyUtil.cacheOrGet(annotationsFileToDataAndModificationStamp, file, pair); data = pair.first;