diff options
author | Stephan Wahlbrink | 2017-02-14 21:31:38 +0000 |
---|---|---|
committer | Stephan Wahlbrink | 2017-10-02 14:23:29 +0000 |
commit | f6cbef0fbeb58de396c726cd343fa177ca109099 (patch) | |
tree | 120bcb64dd6255b1e24e8b97fb035b388979cd1d /org.eclipse.jface.text/src | |
parent | c0fff7329a305c870dc1703914806cb8ef66c57b (diff) | |
download | eclipse.platform.text-f6cbef0fbeb58de396c726cd343fa177ca109099.tar.gz eclipse.platform.text-f6cbef0fbeb58de396c726cd343fa177ca109099.tar.xz eclipse.platform.text-f6cbef0fbeb58de396c726cd343fa177ca109099.zip |
Bug 512251 - Fix IllegalArgumentException in ContextInformationPopupI20171011-2000I20171011-0305I20171010-2000I20171009-2000I20171008-2000I20171007-1500I20171006-2000I20171005-2000I20171004-2000I20171004-0315I20171003-2000I20171002-2000
Change-Id: I7c6eec0871e7f2b3a2a71c401b19e52a687f126e
Signed-off-by: Stephan Wahlbrink <sw@wahlbrink.eu>
Diffstat (limited to 'org.eclipse.jface.text/src')
2 files changed, 38 insertions, 8 deletions
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistSubjectControlAdapter.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistSubjectControlAdapter.java index 8d648d91b84..af6d754196e 100644 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistSubjectControlAdapter.java +++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistSubjectControlAdapter.java @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Mickael Istria (Red Hat Inc.) - [251156] Allow multiple contentAssitProviders internally & inheritance + * Stephan Wahlbrink <sw@wahlbrink.eu> - Bug 512251 - Fix IllegalArgumentException in ContextInformationPopup *******************************************************************************/ package org.eclipse.jface.text.contentassist; @@ -120,6 +121,14 @@ class ContentAssistSubjectControlAdapter implements IContentAssistSubjectControl return fViewer.getTextWidget().getLineDelimiter(); } + public boolean isValidWidgetOffset(int widgetOffset) { + if (fContentAssistSubjectControl != null) { + IDocument document= fContentAssistSubjectControl.getDocument(); + return (widgetOffset >= 0 && widgetOffset <= document.getLength()); + } + return (widgetOffset >= 0 && widgetOffset <= fViewer.getTextWidget().getCharCount()); + } + @Override public void addKeyListener(KeyListener keyListener) { if (fContentAssistSubjectControl != null) diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationPopup.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationPopup.java index f733d6dad4c..8315265a97f 100644 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationPopup.java +++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationPopup.java @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Wahlbrink <sw@wahlbrink.eu> - Bug 512251 - Fix IllegalArgumentException in ContextInformationPopup *******************************************************************************/ package org.eclipse.jface.text.contentassist; @@ -274,7 +275,7 @@ class ContextInformationPopup implements IContentAssistListener { * @since 3.0 */ private void internalShowContextInfo(ContextFrame frame) { - if (frame != null) { + if (frame != null && canShowFrame(frame)) { fContextFrameStack.push(frame); if (fContextFrameStack.size() == 1) fLastContext= null; @@ -336,6 +337,19 @@ class ContextInformationPopup implements IContentAssistListener { } /** + * Pre-checks if the given context frame can be (re)shown. + * + * The function checks if the frame has valid position data. It does not call the context + * information validator. + * + * @param frame the frame to check + * @return <code>true</code> if the context frame OK to use, otherwise <code>false</code> + */ + private boolean canShowFrame(ContextFrame frame) { + return fContentAssistSubjectControlAdapter.isValidWidgetOffset(frame.fVisibleOffset); + } + + /** * Shows the given context frame. * * @param frame the frame to display @@ -457,16 +471,23 @@ class ContextInformationPopup implements IContentAssistListener { if (Helper.okToUse(fContextInfoPopup)) { int size= fContextFrameStack.size(); - if (size > 0) { + while (size > 0) { fLastContext= fContextFrameStack.pop(); -- size; - } - - if (size > 0) { - ContextFrame current= fContextFrameStack.peek(); - internalShowContextFrame(current, false); - } else { + if (size > 0) { + ContextFrame current= fContextFrameStack.peek(); + if (canShowFrame(current)) { + internalShowContextFrame(current, false); + return; + } + // continue - try next + } + else { + break; + } + } + { fContentAssistant.removeContentAssistListener(this, ContentAssistant.CONTEXT_INFO_POPUP); if (fContentAssistSubjectControlAdapter.getControl() != null) |