diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/AbstractControlContentAssistSubjectAdapter.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/AbstractControlContentAssistSubjectAdapter.java index e13ec43bffe..c9cfa2774c1 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/AbstractControlContentAssistSubjectAdapter.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/AbstractControlContentAssistSubjectAdapter.java @@ -99,8 +99,9 @@ public AbstractControlContentAssistSubjectAdapter() { public void addKeyListener(KeyListener keyListener) { fKeyListeners.add(keyListener); - if (DEBUG) + if (DEBUG) { System.out.println("AbstractControlContentAssistSubjectAdapter#addKeyListener()"); //$NON-NLS-1$ + } installControlListener(); } @@ -110,8 +111,9 @@ public void removeKeyListener(KeyListener keyListener) { boolean deleted= fKeyListeners.remove(keyListener); if (DEBUG) { - if (!deleted) + if (!deleted) { System.out.println("removeKeyListener -> wasn't here"); //$NON-NLS-1$ + } System.out.println("AbstractControlContentAssistSubjectAdapter#removeKeyListener() -> " + fKeyListeners.size()); //$NON-NLS-1$ } @@ -127,8 +129,9 @@ public boolean supportsVerifyKeyListener() { public boolean appendVerifyKeyListener(final VerifyKeyListener verifyKeyListener) { fVerifyKeyListeners.add(verifyKeyListener); - if (DEBUG) + if (DEBUG) { System.out.println("AbstractControlContentAssistSubjectAdapter#appendVerifyKeyListener() -> " + fVerifyKeyListeners.size()); //$NON-NLS-1$ + } installControlListener(); return true; @@ -138,8 +141,9 @@ public boolean appendVerifyKeyListener(final VerifyKeyListener verifyKeyListener public boolean prependVerifyKeyListener(final VerifyKeyListener verifyKeyListener) { fVerifyKeyListeners.add(0, verifyKeyListener); - if (DEBUG) + if (DEBUG) { System.out.println("AbstractControlContentAssistSubjectAdapter#prependVerifyKeyListener() -> " + fVerifyKeyListeners.size()); //$NON-NLS-1$ + } installControlListener(); return true; @@ -149,8 +153,9 @@ public boolean prependVerifyKeyListener(final VerifyKeyListener verifyKeyListene public void removeVerifyKeyListener(VerifyKeyListener verifyKeyListener) { fVerifyKeyListeners.remove(verifyKeyListener); - if (DEBUG) + if (DEBUG) { System.out.println("AbstractControlContentAssistSubjectAdapter#removeVerifyKeyListener() -> " + fVerifyKeyListeners.size()); //$NON-NLS-1$ + } uninstallControlListener(); } @@ -158,8 +163,9 @@ public void removeVerifyKeyListener(VerifyKeyListener verifyKeyListener) { @Override public void setEventConsumer(IEventConsumer eventConsumer) { // this is not supported - if (DEBUG) + if (DEBUG) { System.out.println("AbstractControlContentAssistSubjectAdapter#setEventConsumer()"); //$NON-NLS-1$ + } } @Override @@ -172,24 +178,28 @@ public String getLineDelimiter() { * passing them to {@link #fVerifyKeyListeners} and {@link #fKeyListeners}. */ private void installControlListener() { - if (DEBUG) + if (DEBUG) { System.out.println("AbstractControlContentAssistSubjectAdapter#installControlListener() -> k: " + fKeyListeners.size() + ", v: " + fVerifyKeyListeners.size()); //$NON-NLS-1$ //$NON-NLS-2$ + } - if (fControlListener != null) + if (fControlListener != null) { return; + } fControlListener= new Listener() { @Override public void handleEvent(Event e) { - if (! getControl().isFocusControl()) + if (! getControl().isFocusControl()) { return; //SWT.TRAVERSE_MNEMONIC events can also come in to inactive widgets + } VerifyEvent verifyEvent= new VerifyEvent(e); KeyEvent keyEvent= new KeyEvent(e); switch (e.type) { case SWT.Traverse : - if (DEBUG) + if (DEBUG) { dump("before traverse", e, verifyEvent); //$NON-NLS-1$ + } verifyEvent.doit= true; for (VerifyKeyListener verifyKeyListener : fVerifyKeyListeners) { @@ -197,13 +207,15 @@ public void handleEvent(Event e) { if (! verifyEvent.doit) { e.detail= SWT.TRAVERSE_NONE; e.doit= true; - if (DEBUG) + if (DEBUG) { dump("traverse eaten by verify", e, verifyEvent); //$NON-NLS-1$ + } return; } - if (DEBUG) + if (DEBUG) { dump("traverse OK", e, verifyEvent); //$NON-NLS-1$ + } } break; @@ -212,14 +224,16 @@ public void handleEvent(Event e) { verifyKeyListener.verifyKey(verifyEvent); if (! verifyEvent.doit) { e.doit= verifyEvent.doit; - if (DEBUG) + if (DEBUG) { dump("keyDown eaten by verify", e, verifyEvent); //$NON-NLS-1$ + } return; } } - if (DEBUG) + if (DEBUG) { dump("keyDown OK", e, verifyEvent); //$NON-NLS-1$ + } for (KeyListener keyListener : fKeyListeners) { keyListener.keyPressed(keyEvent); @@ -263,8 +277,9 @@ private String hex(int i) { getControl().addListener(SWT.Traverse, fControlListener); getControl().addListener(SWT.KeyDown, fControlListener); - if (DEBUG) + if (DEBUG) { System.out.println("AbstractControlContentAssistSubjectAdapter#installControlListener() - installed"); //$NON-NLS-1$ + } } /** @@ -275,8 +290,9 @@ private String hex(int i) { private void uninstallControlListener() { if (fControlListener == null || fKeyListeners.size() + fVerifyKeyListeners.size() != 0) { - if (DEBUG) + if (DEBUG) { System.out.println("AbstractControlContentAssistSubjectAdapter#uninstallControlListener() -> k: " + fKeyListeners.size() + ", v: " + fVerifyKeyListeners.size()); //$NON-NLS-1$ //$NON-NLS-2$ + } return; } @@ -284,8 +300,9 @@ private void uninstallControlListener() { getControl().removeListener(SWT.KeyDown, fControlListener); fControlListener= null; - if (DEBUG) + if (DEBUG) { System.out.println("AbstractControlContentAssistSubjectAdapter#uninstallControlListener() - done"); //$NON-NLS-1$ + } } /** @@ -349,8 +366,9 @@ public void setContentAssistCueProvider(final ILabelProvider labelProvider) { ILabelProviderListener listener= event -> { fControlDecoration.setDescriptionText(labelProvider.getText(getControl())); Image image= labelProvider.getImage(getControl()); - if (image == null) + if (image == null) { image= getDefaultCueImage(); + } fControlDecoration.setImage(image); }; labelProvider.addListener(listener); diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/ComboContentAssistSubjectAdapter.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/ComboContentAssistSubjectAdapter.java index 65c7a2476fe..48b44e1b137 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/ComboContentAssistSubjectAdapter.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/ComboContentAssistSubjectAdapter.java @@ -168,7 +168,8 @@ public boolean addSelectionListener(final SelectionListener selectionListener) { public void removeSelectionListener(SelectionListener selectionListener) { fCombo.removeSelectionListener(selectionListener); Listener listener= fModifyListeners.get(selectionListener); - if (listener != null) + if (listener != null) { fCombo.removeListener(SWT.Modify, listener); + } } } diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/SubjectControlContextInformationValidator.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/SubjectControlContextInformationValidator.java index 07e04429ff8..c8ec349b344 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/SubjectControlContextInformationValidator.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/SubjectControlContextInformationValidator.java @@ -65,8 +65,9 @@ public boolean isContextInformationValid(int offset) { IContextInformation[] infos= ((ISubjectControlContentAssistProcessor)fProcessor).computeContextInformation(fContentAssistSubjectControl, offset); if (infos != null && infos.length > 0) { for (IContextInformation info : infos) { - if (fContextInformation.equals(info)) + if (fContextInformation.equals(info)) { return true; + } } } } diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/TextContentAssistSubjectAdapter.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/TextContentAssistSubjectAdapter.java index 87e5405a4b5..862f31e98aa 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/TextContentAssistSubjectAdapter.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/TextContentAssistSubjectAdapter.java @@ -151,7 +151,8 @@ public boolean addSelectionListener(final SelectionListener selectionListener) { public void removeSelectionListener(SelectionListener selectionListener) { fText.removeSelectionListener(selectionListener); Listener listener= fModifyListeners.get(selectionListener); - if (listener != null) + if (listener != null) { fText.removeListener(SWT.Modify, listener); + } } } diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/InformationControlReplacer.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/InformationControlReplacer.java index f34fb4ea1e8..e191e05cbd3 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/InformationControlReplacer.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/InformationControlReplacer.java @@ -89,10 +89,11 @@ public void replaceInformationControl(IInformationControlCreator informationPres try { fIsReplacing= true; - if (! fDelayedInformationSet) + if (! fDelayedInformationSet) { fReplacableInformation= information; - else + } else { takeFocus= true; // delayed input has been set, so the original info control must have been focused + } fContentBounds= contentBounds; fReplaceableArea= subjectArea; @@ -117,8 +118,9 @@ protected void computeInformation() { return; } - if (DEBUG) + if (DEBUG) { System.out.println("InformationControlReplacer: no active replaceable"); //$NON-NLS-1$ + } } /** @@ -136,10 +138,11 @@ public void showInformationControl(Rectangle subjectArea, Object information) { // Caveat: some IInformationControls fail unless setSizeConstraints(..) is called with concrete values informationControl.setSizeConstraints(controlBounds.width, controlBounds.height); - if (informationControl instanceof IInformationControlExtension2) + if (informationControl instanceof IInformationControlExtension2) { ((IInformationControlExtension2) informationControl).setInput(information); - else + } else { informationControl.setInformation(information.toString()); + } // need to recompute the bounds because trim might have changed based on input controlBounds= computeBoundsFromContent(informationControl, fContentBounds); diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/NonDeletingPositionUpdater.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/NonDeletingPositionUpdater.java index 6c71d76941d..99dbf5060e0 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/NonDeletingPositionUpdater.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/NonDeletingPositionUpdater.java @@ -57,8 +57,9 @@ public void update(DocumentEvent event) { Position position= positions[i]; - if (position.isDeleted()) + if (position.isDeleted()) { continue; + } int offset= position.getOffset(); int length= position.getLength(); diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/SelectionProcessor.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/SelectionProcessor.java index 0129ec83a52..835adc4498c 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/SelectionProcessor.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/SelectionProcessor.java @@ -106,8 +106,9 @@ boolean isEmpty(T selection) throws BadLocationException { * @throws BadLocationException if selection is not a valid selection on the target document */ boolean isMultiline(T selection) throws BadLocationException { - if (selection == null) + if (selection == null) { throw new NullPointerException(); + } return false; } @@ -544,8 +545,9 @@ String getText(IBlockTextSelection selection) throws BadLocationException { for (int line= startLine; line <= endLine; line++) { appendColumnRange(buf, line, visualStartColumn, visualEndColumn); - if (line != endLine) + if (line != endLine) { buf.append(fDocument.getLineDelimiter(line)); + } } return buf.toString(); @@ -656,16 +658,18 @@ private TextEdit createReplaceEdit(int line, int visualStartColumn, int visualEn int visual= 0; for (int offset= 0; offset < lineLength; offset++) { if (startColumn == -1) { - if (visual == visualStartColumn) - if (!delete && isWider(content.charAt(offset), visual) && replacement.isEmpty()) + if (visual == visualStartColumn) { + if (!delete && isWider(content.charAt(offset), visual) && replacement.isEmpty()) { startColumn= offset - 1; - else + } else { startColumn= offset; - else if (visual > visualStartColumn) { - if (isWider(content.charAt(offset - 1), visual)) + } + } else if (visual > visualStartColumn) { + if (isWider(content.charAt(offset - 1), visual)) { startColumn= offset - 1; - else + } else { startColumn= offset; + } } } if (startColumn != -1) { @@ -673,10 +677,11 @@ else if (visual > visualStartColumn) { endColumn= offset; break; } else if (visual > visualEndColumn) { - if (!delete && isWider(content.charAt(offset - 1), visual)) + if (!delete && isWider(content.charAt(offset - 1), visual)) { endColumn= offset - 1; - else + } else { endColumn= offset; + } break; } } @@ -692,10 +697,12 @@ else if (visual > visualStartColumn) { } return new MultiTextEdit(); } - if (endColumn == -1) + if (endColumn == -1) { endColumn= lineLength; - if (replacement.isEmpty()) + } + if (replacement.isEmpty()) { return new DeleteEdit(info.getOffset() + startColumn, endColumn - startColumn); + } return new ReplaceEdit(info.getOffset() + startColumn, endColumn - startColumn, replacement); } @@ -707,20 +714,23 @@ private void appendColumnRange(StringBuilder buf, int line, int visualStartColum int endColumn= -1; int visual= 0; for (int offset= 0; offset < lineLength; offset++) { - if (startColumn == -1 && visual >= visualStartColumn) + if (startColumn == -1 && visual >= visualStartColumn) { startColumn= offset; + } if (visual >= visualEndColumn) { endColumn= offset; break; } visual+= visualSizeIncrement(content.charAt(offset), visual); } - if (startColumn != -1) + if (startColumn != -1) { buf.append(content.substring(startColumn, endColumn == -1 ? lineLength : endColumn)); + } if (endColumn == -1) { int spaces= Math.max(0, visualEndColumn - Math.max(visual, visualStartColumn)); - for (int i= 0; i < spaces; i++) + for (int i= 0; i < spaces; i++) { buf.append(' '); + } } } @@ -730,10 +740,12 @@ private int computeVisualColumn(final int line, final int column) throws BadLoca int to= Math.min(lineLength, column); String content= fDocument.get(info.getOffset(), lineLength); int visual= 0; - for (int offset= 0; offset < to; offset++) + for (int offset= 0; offset < to; offset++) { visual+= visualSizeIncrement(content.charAt(offset), visual); - if (column > lineLength) + } + if (column > lineLength) { visual+= column - lineLength; // virtual spaces + } return visual; } @@ -743,8 +755,9 @@ private int computeCharacterColumn(int line, int visualColumn) throws BadLocatio String content= fDocument.get(info.getOffset(), lineLength); int visual= 0; for (int offset= 0; offset < lineLength; offset++) { - if (visual >= visualColumn) + if (visual >= visualColumn) { return offset; + } visual+= visualSizeIncrement(content.charAt(offset), visual); } return lineLength + Math.max(0, visualColumn - visual); @@ -773,14 +786,17 @@ private int visualSizeIncrement(char character, int visual) { int singleCharWidth= gc.stringExtent(" ").x; //$NON-NLS-1$ return (int) Math.ceil((double) charWidth / singleCharWidth); } finally { - if (gc != null) + if (gc != null) { gc.dispose(); + } } } - if (character != '\t') + if (character != '\t') { return 1; - if (fTabWidth <= 0) + } + if (fTabWidth <= 0) { return 0; + } return fTabWidth - visual % fTabWidth; } }; @@ -935,8 +951,9 @@ private ISelection makeDeleteSelection(ISelection selection) throws BadLocationE public void doDelete(ISelection selection) throws BadLocationException { TextEdit edit= delete(selection); boolean complex= edit.hasChildren(); - if (complex && fRewriteTarget != null) + if (complex && fRewriteTarget != null) { fRewriteTarget.beginCompoundChange(); + } try { edit.apply(fDocument, TextEdit.UPDATE_REGIONS); if (fSelectionProvider != null) { @@ -944,9 +961,10 @@ public void doDelete(ISelection selection) throws BadLocationException { fSelectionProvider.setSelection(empty); } } finally { - if (complex && fRewriteTarget != null) + if (complex && fRewriteTarget != null) { fRewriteTarget.endCompoundChange(); } + } } /** @@ -959,8 +977,9 @@ public void doDelete(ISelection selection) throws BadLocationException { public void doBackspace(ISelection selection) throws BadLocationException { TextEdit edit= backspace(selection); boolean complex= edit.hasChildren(); - if (complex && fRewriteTarget != null) + if (complex && fRewriteTarget != null) { fRewriteTarget.beginCompoundChange(); + } try { ISelection newSelection= makeBackspaceSelection(selection); edit.apply(fDocument, TextEdit.UPDATE_REGIONS); @@ -968,8 +987,9 @@ public void doBackspace(ISelection selection) throws BadLocationException { fSelectionProvider.setSelection(newSelection); } } finally { - if (complex && fRewriteTarget != null) + if (complex && fRewriteTarget != null) { fRewriteTarget.endCompoundChange(); + } } } @@ -984,8 +1004,9 @@ public void doBackspace(ISelection selection) throws BadLocationException { public void doReplace(ISelection selection, String replacement) throws BadLocationException { TextEdit edit= replace(selection, replacement); boolean complex= edit.hasChildren(); - if (complex && fRewriteTarget != null) + if (complex && fRewriteTarget != null) { fRewriteTarget.beginCompoundChange(); + } try { edit.apply(fDocument, TextEdit.UPDATE_REGIONS); @@ -994,8 +1015,9 @@ public void doReplace(ISelection selection, String replacement) throws BadLocati fSelectionProvider.setSelection(empty); } } finally { - if (complex && fRewriteTarget != null) + if (complex && fRewriteTarget != null) { fRewriteTarget.endCompoundChange(); + } } } diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/StickyHoverManager.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/StickyHoverManager.java index 35456f83cf3..a4801442c8c 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/StickyHoverManager.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/StickyHoverManager.java @@ -100,8 +100,9 @@ public void setInformationControl(IInformationControl control) { @Override public void start(Rectangle informationArea) { - if (fIsActive) + if (fIsActive) { return; + } fIsActive= true; if (fSubjectControl != null && !fSubjectControl.isDisposed()) { @@ -113,8 +114,9 @@ public void start(Rectangle informationArea) { fTextViewer.addViewportListener(this); IInformationControl fInformationControlToClose= getCurrentInformationControl2(); - if (fInformationControlToClose != null) + if (fInformationControlToClose != null) { fInformationControlToClose.addFocusListener(this); + } fDisplay= fSubjectControl.getDisplay(); if (!fDisplay.isDisposed()) { @@ -126,8 +128,9 @@ public void start(Rectangle informationArea) { @Override public void stop() { - if (!fIsActive) + if (!fIsActive) { return; + } fIsActive= false; fTextViewer.removeViewportListener(this); @@ -139,8 +142,9 @@ public void stop() { } IInformationControl fInformationControlToClose= getCurrentInformationControl2(); - if (fInformationControlToClose != null) + if (fInformationControlToClose != null) { fInformationControlToClose.removeFocusListener(this); + } if (fDisplay != null && !fDisplay.isDisposed()) { fDisplay.removeFilter(SWT.MouseMove, this); @@ -194,7 +198,9 @@ public void focusGained(FocusEvent e) { @Override public void focusLost(FocusEvent e) { - if (DEBUG) System.out.println("StickyHoverManager.Closer.focusLost(): " + e); //$NON-NLS-1$ + if (DEBUG) { + System.out.println("StickyHoverManager.Closer.focusLost(): " + e); //$NON-NLS-1$ + } Display d= fSubjectControl.getDisplay(); // Without the asyncExec, mouse clicks to the workbench window are swallowed. d.asyncExec(() -> hideInformationControl()); @@ -203,8 +209,9 @@ public void focusLost(FocusEvent e) { @Override public void handleEvent(Event event) { if (event.type == SWT.MouseMove) { - if (!(event.widget instanceof Control) || event.widget.isDisposed()) + if (!(event.widget instanceof Control) || event.widget.isDisposed()) { return; + } IInformationControl infoControl= getCurrentInformationControl2(); if (infoControl != null && !infoControl.isFocusControl() && infoControl instanceof IInformationControlExtension3 iControl3) { @@ -224,15 +231,19 @@ public void handleEvent(Event event) { * TODO: need better understanding of why/if this is needed. * Looks like the same panic code we have in org.eclipse.jface.text.AbstractHoverInformationControlManager.Closer.handleMouseMove(Event) */ - if (fDisplay != null && !fDisplay.isDisposed()) + if (fDisplay != null && !fDisplay.isDisposed()) { fDisplay.removeFilter(SWT.MouseMove, this); + } } } else if (event.type == SWT.FocusOut) { - if (DEBUG) System.out.println("StickyHoverManager.Closer.handleEvent(): focusOut: " + event); //$NON-NLS-1$ + if (DEBUG) { + System.out.println("StickyHoverManager.Closer.handleEvent(): focusOut: " + event); //$NON-NLS-1$ + } IInformationControl iControl= getCurrentInformationControl2(); - if (iControl != null && ! iControl.isFocusControl()) + if (iControl != null && ! iControl.isFocusControl()) { hideInformationControl(); + } } } } @@ -257,11 +268,12 @@ public StickyHoverManager(TextViewer textViewer) { @Override protected void showInformationControl(Rectangle subjectArea) { - if (fTextViewer != null && fTextViewer.requestWidgetToken(this, WIDGET_PRIORITY)) + if (fTextViewer != null && fTextViewer.requestWidgetToken(this, WIDGET_PRIORITY)) { super.showInformationControl(subjectArea); - else - if (DEBUG) + } else + if (DEBUG) { System.out.println("cancelled StickyHoverManager.showInformationControl(..): did not get widget token (with prio)"); //$NON-NLS-1$ + } } @Override @@ -269,8 +281,9 @@ public void hideInformationControl() { try { super.hideInformationControl(); } finally { - if (fTextViewer != null) + if (fTextViewer != null) { fTextViewer.releaseWidgetToken(this); + } } } @@ -279,16 +292,18 @@ protected void handleInformationControlDisposed() { try { super.handleInformationControlDisposed(); } finally { - if (fTextViewer != null) + if (fTextViewer != null) { fTextViewer.releaseWidgetToken(this); + } } } @Override public boolean requestWidgetToken(IWidgetTokenOwner owner) { hideInformationControl(); - if (DEBUG) + if (DEBUG) { System.out.println("StickyHoverManager gave up widget token (no prio)"); //$NON-NLS-1$ + } return true; } @@ -296,22 +311,26 @@ public boolean requestWidgetToken(IWidgetTokenOwner owner) { public boolean requestWidgetToken(IWidgetTokenOwner owner, int priority) { if (getCurrentInformationControl2() != null) { if (getCurrentInformationControl2().isFocusControl()) { - if (DEBUG) + if (DEBUG) { System.out.println("StickyHoverManager kept widget token (focused)"); //$NON-NLS-1$ + } return false; } else if (priority > WIDGET_PRIORITY) { hideInformationControl(); - if (DEBUG) + if (DEBUG) { System.out.println("StickyHoverManager gave up widget token (prio)"); //$NON-NLS-1$ + } return true; } else { - if (DEBUG) + if (DEBUG) { System.out.println("StickyHoverManager kept widget token (prio)"); //$NON-NLS-1$ + } return false; } } - if (DEBUG) + if (DEBUG) { System.out.println("StickyHoverManager gave up widget token (no iControl)"); //$NON-NLS-1$ + } return true; } diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/BrowserInformationControl.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/BrowserInformationControl.java index 6042241b376..1e79dc782f4 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/BrowserInformationControl.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/BrowserInformationControl.java @@ -281,13 +281,15 @@ public void setInput(Object input) { fInput= (BrowserInformationControlInput)input; String content= null; - if (fInput != null) + if (fInput != null) { content= fInput.getHtml(); + } fBrowserHasContent= content != null && !content.isEmpty(); - if (!fBrowserHasContent) + if (!fBrowserHasContent) { content= ""; //$NON-NLS-1$ + } boolean RTL= (getShell().getStyle() & SWT.RIGHT_TO_LEFT) != 0; boolean resizable= isResizable(); @@ -300,16 +302,17 @@ public void setInput(Object input) { // The default "overflow:auto" would not result in a predictable width for the client area // and the re-wrapping would cause visual noise String[] styles= null; - if (RTL && resizable) + if (RTL && resizable) { styles= new String[] { "direction:rtl;", scrollbarStyle, "word-wrap:break-word;" }; //$NON-NLS-1$ //$NON-NLS-2$ - else if (RTL && !resizable) + } else if (RTL && !resizable) { styles= new String[] { "direction:rtl;", "overflow:hidden;", "word-wrap:break-word;" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - else if (!resizable) + } else if (!resizable) { //XXX: In IE, "word-wrap: break-word;" causes bogus wrapping even in non-broken words :-(see e.g. Javadoc of String). // Re-check whether we really still need this now that the Javadoc Hover header already sets this style. styles= new String[] { "overflow:hidden;"/*, "word-wrap: break-word;"*/}; //$NON-NLS-1$ - else + } else { styles= new String[] { scrollbarStyle }; + } StringBuilder buffer= new StringBuilder(content); HTMLPrinter.insertStyles(buffer, styles); @@ -340,8 +343,9 @@ public void setVisible(boolean visible) { return; } - if (shell.isVisible() == visible) + if (shell.isVisible() == visible) { return; + } /* * The Browser widget flickers when made visible while it is not completely loaded. * The fix is to delay the call to setVisible until either loading is completed @@ -360,15 +364,17 @@ public void setVisible(boolean visible) { } shell= getShell(); - if (shell == null || shell.isDisposed()) + if (shell == null || shell.isDisposed()) { return; + } /* * Avoids flickering when replacing hovers, especially on Vista in ON_CLICK mode. * Causes flickering on GTK. Carbon does not care. */ - if (Util.isWin32()) + if (Util.isWin32()) { shell.moveAbove(null); + } super.setVisible(true); } @@ -440,8 +446,9 @@ public Point computeSizeHint() { Iterator iter= presentation.getAllStyleRangeIterator(); while (iter.hasNext()) { StyleRange sr= iter.next(); - if (sr.fontStyle == SWT.BOLD) + if (sr.fontStyle == SWT.BOLD) { fTextLayout.setStyle(fBoldStyle, sr.start, sr.start + sr.length - 1); + } } Rectangle bounds= fTextLayout.getBounds(); // does not return minimum width, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=217446 @@ -450,8 +457,9 @@ public Point computeSizeHint() { for (int i= 0; i < lineCount; i++) { Rectangle rect= fTextLayout.getLineBounds(i); int lineWidth= rect.x + rect.width; - if (i == 0) + if (i == 0) { lineWidth+= fInput.getLeadingImageWidth(); + } textWidth= Math.max(textWidth, lineWidth); } bounds.width= textWidth; @@ -467,10 +475,12 @@ public Point computeSizeHint() { // Apply max size constraints if (sizeConstraints != null) { - if (sizeConstraints.x != SWT.DEFAULT) + if (sizeConstraints.x != SWT.DEFAULT) { minWidth= Math.min(sizeConstraints.x, minWidth + trim.width); - if (sizeConstraints.y != SWT.DEFAULT) + } + if (sizeConstraints.y != SWT.DEFAULT) { height= Math.min(sizeConstraints.y, height); + } } // Ensure minimal size @@ -568,8 +578,9 @@ public boolean hasDelayedInputChangeListener() { * @since 3.4 */ public void notifyDelayedInputChange(Object newInput) { - if (fDelayedInputChangeListener != null) + if (fDelayedInputChangeListener != null) { fDelayedInputChangeListener.inputChanged(newInput); + } } @Override @@ -587,8 +598,9 @@ public BrowserInformationControlInput getInput() { @Override public Point computeSizeConstraints(int widthInChars, int heightInChars) { - if (fSymbolicFontName == null) + if (fSymbolicFontName == null) { return null; + } GC gc= new GC(fBrowser); Font font= JFaceResources.getFont(fSymbolicFontName); diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/BrowserInput.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/BrowserInput.java index 9bc622a3c78..8f3822cd4c6 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/BrowserInput.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/BrowserInput.java @@ -35,8 +35,9 @@ public abstract class BrowserInput { */ public BrowserInput(BrowserInput previous) { fPrevious= previous; - if (previous != null) + if (previous != null) { previous.fNext= this; + } } /** diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/HTML2TextReader.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/HTML2TextReader.java index 1ad32765258..fb5ac10fc5b 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/HTML2TextReader.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/HTML2TextReader.java @@ -106,8 +106,9 @@ public HTML2TextReader(Reader reader, TextPresentation presentation) { @Override public int read() throws IOException { int c= super.read(); - if (c != -1) + if (c != -1) { ++ fCounter; + } return c; } @@ -185,29 +186,33 @@ protected void stopPreformattedText() { @Override protected String computeSubstitution(int c) throws IOException { - if (c == '<') + if (c == '<') { return processHTMLTag(); - else if (fIgnore) + } else if (fIgnore) { return EMPTY_STRING; - else if (c == '&') + } else if (c == '&') { return processEntity(); + } return null; } private String html2Text(String html) { - if (html == null || html.isEmpty()) + if (html == null || html.isEmpty()) { return EMPTY_STRING; + } html= html.toLowerCase(); String tag= html; - if ('/' == tag.charAt(0)) + if ('/' == tag.charAt(0)) { tag= tag.substring(1); + } - if (!fgTags.contains(tag)) + if (!fgTags.contains(tag)) { return EMPTY_STRING; + } if ("pre".equals(html)) { //$NON-NLS-1$ @@ -245,15 +250,18 @@ private String html2Text(String html) { return EMPTY_STRING; } - if ("dl".equals(html)) //$NON-NLS-1$ + if ("dl".equals(html)) { //$NON-NLS-1$ return LINE_DELIM; + } - if ("dd".equals(html)) //$NON-NLS-1$ + if ("dd".equals(html)) { //$NON-NLS-1$ return "\t"; //$NON-NLS-1$ + } - if ("li".equals(html)) //$NON-NLS-1$ + if ("li".equals(html)) { //$NON-NLS-1$ // FIXME: this hard-coded prefix does not work for RTL languages, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=91682 return LINE_DELIM + HTMLMessages.getString("HTML2TextReader.listItemPrefix"); //$NON-NLS-1$ + } if ("/b".equals(html) || "/strong".equals(html)) { //$NON-NLS-1$ //$NON-NLS-2$ stopBold(); @@ -270,8 +278,9 @@ private String html2Text(String html) { return LINE_DELIM; } - if ("br".equals(html) || "br/".equals(html) || "div".equals(html)) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + if ("br".equals(html) || "br/".equals(html) || "div".equals(html)) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ return LINE_DELIM; + } if ("/p".equals(html)) { //$NON-NLS-1$ boolean inParagraph= fInParagraph; @@ -284,8 +293,9 @@ private String html2Text(String html) { return LINE_DELIM; } - if ("/dd".equals(html)) //$NON-NLS-1$ + if ("/dd".equals(html)) { //$NON-NLS-1$ return LINE_DELIM; + } if ("head".equals(html) && !fHeaderDetected) { //$NON-NLS-1$ fHeaderDetected= true; @@ -329,8 +339,9 @@ private String processHTMLTag() throws IOException { } } - if (ch == -1) + if (ch == -1) { return null; + } if (!isInComment(buf) || isCommentEnd(buf)) { break; @@ -388,12 +399,14 @@ private String processEntity() throws IOException { ch= nextChar(); } - if (ch == ';') + if (ch == ';') { return entity2Text(buf.toString()); + } buf.insert(0, '&'); - if (ch != -1) + if (ch != -1) { buf.append((char) ch); + } return buf.toString(); } } diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/HTMLMessages.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/HTMLMessages.java index 8791289b892..58887affe1f 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/HTMLMessages.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/HTMLMessages.java @@ -77,8 +77,9 @@ public static String getFormattedString(String key, Object arg) { } catch (MissingResourceException e) { return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$ } - if (arg == null) + if (arg == null) { arg= ""; //$NON-NLS-1$ + } return MessageFormat.format(format, arg); } } diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/HTMLPrinter.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/HTMLPrinter.java index d8d1fe23eb8..ecaf40de521 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/HTMLPrinter.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/HTMLPrinter.java @@ -48,8 +48,9 @@ public class HTMLPrinter { }); } catch (SWTError err) { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=45294 - if (err.code != SWT.ERROR_DEVICE_DISPOSED) + if (err.code != SWT.ERROR_DEVICE_DISPOSED) { throw err; + } } } } diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/HTMLTextPresenter.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/HTMLTextPresenter.java index 3090f4f14b2..f88a14482b8 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/HTMLTextPresenter.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/HTMLTextPresenter.java @@ -70,8 +70,9 @@ public String updatePresentation(Display display, String hoverInfo, TextPresenta @Override public String updatePresentation(Drawable drawable, String hoverInfo, TextPresentation presentation, int maxWidth, int maxHeight) { - if (hoverInfo == null) + if (hoverInfo == null) { return null; + } if (!fEnforceUpperLineLimit) { maxHeight= Integer.MAX_VALUE; diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/SubstitutionTextReader.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/SubstitutionTextReader.java index 523384a0d00..eca59c9e706 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/SubstitutionTextReader.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/SubstitutionTextReader.java @@ -118,10 +118,12 @@ public int read() throws IOException { c= nextChar(); while (!fReadFromBuffer && c != -1) { String s= computeSubstitution(c); - if (s == null) + if (s == null) { break; - if (!s.isEmpty()) + } + if (!s.isEmpty()) { fBuffer.insert(0, s); + } c= nextChar(); } diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/AdditionalInfoController2.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/AdditionalInfoController2.java index c851704b3fd..a3c5930b2f4 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/AdditionalInfoController2.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/AdditionalInfoController2.java @@ -101,8 +101,9 @@ public void install(Control control) { fProposalTable= (Table) control; fProposalTable.addSelectionListener(fSelectionListener); synchronized (fThreadAccess) { - if (fThread != null) - fThread.interrupt(); + if (fThread != null) { + fThread.interrupt(); + } fThread= new Thread(this, ContentAssistMessages.getString("InfoPopup.info_delay_timer_name")); //$NON-NLS-1$ fStartSignal= new Object(); @@ -156,15 +157,17 @@ public void run() { fIsReset= false; // Delay before showing the popup. fMutex.wait(fDelay); - if (!fIsReset) + if (!fIsReset) { break; + } } } if (fProposalTable != null && !fProposalTable.isDisposed()) { fProposalTable.getDisplay().asyncExec(() -> { - if (!fIsReset) + if (!fIsReset) { showInformation(); + } }); } @@ -174,8 +177,9 @@ public void run() { synchronized (fThreadAccess) { // only set to 'null' if fThread is us! - if (Thread.currentThread() == fThread) + if (Thread.currentThread() == fThread) { fThread= null; + } } } @@ -195,8 +199,9 @@ public void handleTableSelectionChanged() { @Override protected void computeInformation() { - if (fProposalTable == null || fProposalTable.isDisposed()) + if (fProposalTable == null || fProposalTable.isDisposed()) { return; + } TableItem[] selection= fProposalTable.getSelection(); if (selection != null && selection.length > 0) { @@ -211,10 +216,11 @@ protected void computeInformation() { information= p.getAdditionalProposalInfo(); } - if (d instanceof ICompletionProposalExtension3) + if (d instanceof ICompletionProposalExtension3) { setCustomInformationControlCreator(((ICompletionProposalExtension3) d).getInformationControlCreator()); - else + } else { setCustomInformationControlCreator(null); + } // compute subject area setMargins(4, -1); @@ -232,10 +238,12 @@ protected Point computeSizeConstraints(Control subjectControl, IInformationContr // at least as big as the proposal table Point sizeConstraint= super.computeSizeConstraints(subjectControl, informationControl); Point size= subjectControl.getSize(); - if (sizeConstraint.x < size.x) + if (sizeConstraint.x < size.x) { sizeConstraint.x= size.x; - if (sizeConstraint.y < size.y) + } + if (sizeConstraint.y < size.y) { sizeConstraint.y= size.y; + } return sizeConstraint; } } diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/CompletionProposalPopup2.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/CompletionProposalPopup2.java index 6ff47bb09b3..df36199fa15 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/CompletionProposalPopup2.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/CompletionProposalPopup2.java @@ -179,27 +179,31 @@ public String showProposals(final boolean autoActivated) { fKeyListener= new KeyListener() { @Override public void keyPressed(KeyEvent e) { - if (!isValid(fProposalShell)) + if (!isValid(fProposalShell)) { return; + } if (e.character == 0 && e.keyCode == SWT.CTRL) { // http://dev.eclipse.org/bugs/show_bug.cgi?id=34754 int index= fProposalTable.getSelectionIndex(); - if (index >= 0) + if (index >= 0) { selectProposal(index, true); + } } } @Override public void keyReleased(KeyEvent e) { - if (!isValid(fProposalShell)) + if (!isValid(fProposalShell)) { return; + } if (e.character == 0 && e.keyCode == SWT.CTRL) { // http://dev.eclipse.org/bugs/show_bug.cgi?id=34754 int index= fProposalTable.getSelectionIndex(); - if (index >= 0) + if (index >= 0) { selectProposal(index, false); + } } } }; @@ -257,8 +261,9 @@ private String getErrorMessage() { * Creates the proposal selector. */ private void createProposalSelector() { - if (isValid(fProposalShell)) + if (isValid(fProposalShell)) { return; + } Control control= fViewer.getTextWidget(); fProposalShell= new Shell(control.getShell(), SWT.ON_TOP); @@ -268,12 +273,14 @@ private void createProposalSelector() { fIsColoredLabelsSupportEnabled= fContentAssistant.isColoredLabelsSupportEnabled(); - if (fIsColoredLabelsSupportEnabled) + if (fIsColoredLabelsSupportEnabled) { TableOwnerDrawSupport.install(fProposalTable); + } fProposalTable.setLocation(0, 0); - if (fAdditionalInfoController != null) + if (fAdditionalInfoController != null) { fAdditionalInfoController.setSizeConstraints(50, 10, true, false); + } GridLayout layout= new GridLayout(); layout.marginWidth= 0; @@ -288,8 +295,9 @@ private void createProposalSelector() { // set location Point currentLocation= fProposalShell.getLocation(); Point newLocation= getLocation(); - if ((newLocation.x < currentLocation.x && newLocation.y == currentLocation.y) || newLocation.y < currentLocation.y) + if ((newLocation.x < currentLocation.x && newLocation.y == currentLocation.y) || newLocation.y < currentLocation.y) { fProposalShell.setLocation(newLocation); + } if (fAdditionalInfoController != null) { fProposalShell.addControlListener(new ControlListener() { @@ -347,8 +355,9 @@ public void widgetDefaultSelected(SelectionEvent e) { */ private ICompletionProposal getSelectedProposal() { int i= fProposalTable.getSelectionIndex(); - if (i < 0 || i >= fFilteredProposals.length) + if (i < 0 || i >= fFilteredProposals.length) { return null; + } return fFilteredProposals[i]; } @@ -360,9 +369,11 @@ private ICompletionProposal getSelectedProposal() { * @since 2.1 */ private boolean selectProposalWithMask(int stateMask) { - if (fInvocationCounter != fInvocationProcessedCounter) - if (!doFilterProposals()) + if (fInvocationCounter != fInvocationProcessedCounter) { + if (!doFilterProposals()) { return false; + } + } ICompletionProposal p= getSelectedProposal(); hide(); @@ -397,8 +408,9 @@ private void insertProposal(ICompletionProposal p, char trigger, int stateMask, target= extension.getRewriteTarget(); } - if (target != null) + if (target != null) { target.beginCompoundChange(); + } if (fViewer instanceof IEditingSupportRegistry) { registry= (IEditingSupportRegistry) fViewer; @@ -426,8 +438,9 @@ private void insertProposal(ICompletionProposal p, char trigger, int stateMask, if (p instanceof ICompletionProposalExtension e) { position= e.getContextInformationPosition(); } else { - if (selection == null) + if (selection == null) { selection= fViewer.getSelectedRange(); + } position= selection.x + selection.y; } @@ -437,11 +450,13 @@ private void insertProposal(ICompletionProposal p, char trigger, int stateMask, fContentAssistant.fireProposalChosen(p); } finally { - if (target != null) + if (target != null) { target.endCompoundChange(); + } - if (registry != null) + if (registry != null) { registry.unregister(fModificationEditingSupport); + } fInserting= false; } @@ -453,8 +468,9 @@ private void insertProposal(ICompletionProposal p, char trigger, int stateMask, * @return true if the popup has the focus */ public boolean hasFocus() { - if (isValid(fProposalShell)) + if (isValid(fProposalShell)) { return (fProposalShell.isFocusControl() || fProposalTable.isFocusControl()); + } return false; } @@ -488,15 +504,17 @@ public void hide() { private void unregister() { if (fDocumentListener != null) { IDocument document= fViewer.getDocument(); - if (document != null) + if (document != null) { document.removeDocumentListener(fDocumentListener); + } fDocumentListener= null; } fDocumentEvents.clear(); StyledText styledText= fViewer.getTextWidget(); - if (fKeyListener != null && styledText != null && !styledText.isDisposed()) + if (fKeyListener != null && styledText != null && !styledText.isDisposed()) { styledText.removeKeyListener(fKeyListener); + } if (fLastProposal != null) { if (fLastProposal instanceof ICompletionProposalExtension2 extension) { @@ -529,8 +547,9 @@ private void setProposals(ICompletionProposal[] proposals) { if (isValid(fProposalTable)) { ICompletionProposal oldProposal= getSelectedProposal(); - if (oldProposal instanceof ICompletionProposalExtension2) + if (oldProposal instanceof ICompletionProposalExtension2) { ((ICompletionProposalExtension2) oldProposal).unselected(fViewer); + } fFilteredProposals= proposals; @@ -544,16 +563,18 @@ private void setProposals(ICompletionProposal[] proposals) { endOffset= selection.x + selection.y; IDocument document= fViewer.getDocument(); boolean validate= false; - if (selection.y != 0 && document != null) + if (selection.y != 0 && document != null) { validate= true; + } TableItem item; ICompletionProposal p; for (int i= 0; i < proposals.length; i++) { p= proposals[i]; item= new TableItem(fProposalTable, SWT.NULL); - if (p.getImage() != null) + if (p.getImage() != null) { item.setImage(p.getImage()); + } String displayString; StyleRange[] styleRanges= null; @@ -561,12 +582,14 @@ private void setProposals(ICompletionProposal[] proposals) { StyledString styledString= ((ICompletionProposalExtension6)p).getStyledDisplayString(); displayString= styledString.getString(); styleRanges= styledString.getStyleRanges(); - } else + } else { displayString= p.getDisplayString(); + } item.setText(displayString); - if (fIsColoredLabelsSupportEnabled) + if (fIsColoredLabelsSupportEnabled) { TableOwnerDrawSupport.storeStyleRanges(item, 0, styleRanges); + } item.setData(p); @@ -610,11 +633,13 @@ private void resizeProposalSelector(boolean adjustWidth) { * @return the height hint for table */ private int getTableHeightHint(Table table, int rows) { - if (table.getFont().equals(JFaceResources.getDefaultFont())) + if (table.getFont().equals(JFaceResources.getDefaultFont())) { table.setFont(JFaceResources.getDialogFont()); + } int result= table.getItemHeight() * rows; - if (table.getLinesVisible()) + if (table.getLinesVisible()) { result+= table.getGridLineWidth() * (rows - 1); + } // TODO adjust to correct size. +4 works on windows, but not others // return result + 4; @@ -624,11 +649,13 @@ private int getTableHeightHint(Table table, int rows) { private boolean validateProposal(IDocument document, ICompletionProposal p, int offset, DocumentEvent event) { // detect selected if (p instanceof ICompletionProposalExtension2 e) { - if (e.validate(document, offset, event)) + if (e.validate(document, offset, event)) { return true; + } } else if (p instanceof ICompletionProposalExtension e) { - if (e.isValidFor(document, offset)) + if (e.isValidFor(document, offset)) { return true; + } } return false; } @@ -643,8 +670,12 @@ private Point getLocation() { Point selection= text.getSelection(); Point p= text.getLocationAtOffset(selection.x); p.x -= fProposalShell.getBorderWidth(); - if (p.x < 0) p.x= 0; - if (p.y < 0) p.y= 0; + if (p.x < 0) { + p.x= 0; + } + if (p.y < 0) { + p.y= 0; + } p= new Point(p.x, p.y + text.getLineHeight(selection.x)); p= text.toDisplay(p); return p; @@ -657,23 +688,27 @@ private Point getLocation() { private void displayProposals() { if (fContentAssistant.addContentAssistListener(this, ContentAssistant2.PROPOSAL_SELECTOR)) { - if (fDocumentListener == null) + if (fDocumentListener == null) { fDocumentListener= new IDocumentListener() { @Override public void documentAboutToBeChanged(DocumentEvent event) { - if (!fInserting) + if (!fInserting) { fDocumentEvents.add(event); + } } @Override public void documentChanged(DocumentEvent event) { - if (!fInserting) + if (!fInserting) { filterProposals(); + } } }; + } IDocument document= fViewer.getDocument(); - if (document != null) + if (document != null) { document.addDocumentListener(fDocumentListener); + } if (fViewer instanceof IEditingSupportRegistry registry) { @@ -684,8 +719,9 @@ public void documentChanged(DocumentEvent event) { // see bug 47511: setVisible may run the event loop on GTK // and trigger a rentrant call - have to check whether we are still // visible - if (!isValid(fProposalShell)) + if (!isValid(fProposalShell)) { return; + } if (fAdditionalInfoController != null) { @@ -697,8 +733,9 @@ public void documentChanged(DocumentEvent event) { @Override public boolean verifyKey(VerifyEvent e) { - if (!isValid(fProposalShell)) + if (!isValid(fProposalShell)) { return true; + } char key= e.character; if (key == 0) { @@ -713,26 +750,30 @@ public boolean verifyKey(VerifyEvent e) { case SWT.ARROW_UP : newSelection -= 1; - if (newSelection < 0) + if (newSelection < 0) { newSelection= fProposalTable.getItemCount() - 1; + } break; case SWT.ARROW_DOWN : newSelection += 1; - if (newSelection > fProposalTable.getItemCount() - 1) + if (newSelection > fProposalTable.getItemCount() - 1) { newSelection= 0; + } break; case SWT.PAGE_DOWN : newSelection += visibleRows; - if (newSelection >= fProposalTable.getItemCount()) + if (newSelection >= fProposalTable.getItemCount()) { newSelection= fProposalTable.getItemCount() - 1; + } break; case SWT.PAGE_UP : newSelection -= visibleRows; - if (newSelection < 0) + if (newSelection < 0) { newSelection= 0; + } break; case SWT.HOME : @@ -744,8 +785,9 @@ public boolean verifyKey(VerifyEvent e) { break; default : - if (e.keyCode != SWT.MOD1 && e.keyCode != SWT.MOD2 && e.keyCode != SWT.MOD3 && e.keyCode != SWT.MOD4) + if (e.keyCode != SWT.MOD1 && e.keyCode != SWT.MOD2 && e.keyCode != SWT.MOD3 && e.keyCode != SWT.MOD4) { hide(); + } return true; } @@ -802,19 +844,22 @@ public boolean verifyKey(VerifyEvent e) { private void selectProposal(int index, boolean smartToggle) { ICompletionProposal oldProposal= getSelectedProposal(); - if (oldProposal instanceof ICompletionProposalExtension2) + if (oldProposal instanceof ICompletionProposalExtension2) { ((ICompletionProposalExtension2) oldProposal).unselected(fViewer); + } ICompletionProposal proposal= fFilteredProposals[index]; - if (proposal instanceof ICompletionProposalExtension2) + if (proposal instanceof ICompletionProposalExtension2) { ((ICompletionProposalExtension2) proposal).selected(fViewer, smartToggle); + } fLastProposal= proposal; fProposalTable.setSelection(index); fProposalTable.showSelection(); - if (fAdditionalInfoController != null) + if (fAdditionalInfoController != null) { fAdditionalInfoController.handleTableSelectionChanged(); + } } /** @@ -828,12 +873,14 @@ private void selectProposal(int index, boolean smartToggle) { */ private boolean contains(char[] characters, char c) { - if (characters == null) + if (characters == null) { return false; + } for (char character : characters) { - if (c == character) + if (c == character) { return true; + } } return false; @@ -851,10 +898,12 @@ private void filterProposals() { Control control= fViewer.getTextWidget(); long fCounter= fInvocationCounter; control.getDisplay().asyncExec(() -> { - if (fCounter != fInvocationCounter) + if (fCounter != fInvocationCounter) { return; - if (fInvocationProcessedCounter == fInvocationCounter) + } + if (fInvocationProcessedCounter == fInvocationCounter) { return; + } doFilterProposals(); }); @@ -902,19 +951,22 @@ public boolean doFilterProposals() { */ private ICompletionProposal[] computeFilteredProposals(int offset, DocumentEvent event) { - if (offset == fInvocationOffset && event == null) + if (offset == fInvocationOffset && event == null) { return fComputedProposals; + } if (offset < fInvocationOffset) { return null; } ICompletionProposal[] proposals= fComputedProposals; - if (offset > fFilterOffset) + if (offset > fFilterOffset) { proposals= fFilteredProposals; + } - if (proposals == null) + if (proposals == null) { return null; + } IDocument document= fViewer.getDocument(); int length= proposals.length; @@ -923,13 +975,15 @@ private ICompletionProposal[] computeFilteredProposals(int offset, DocumentEvent if (proposals[i] instanceof ICompletionProposalExtension2 p) { - if (p.validate(document, offset, event)) + if (p.validate(document, offset, event)) { filtered.add(p); + } } else if (proposals[i] instanceof ICompletionProposalExtension p) { - if (p.isValidFor(document, offset)) + if (p.isValidFor(document, offset)) { filtered.add(p); + } } else { // restore original behavior @@ -950,7 +1004,8 @@ private ICompletionProposal[] computeFilteredProposals(int offset, DocumentEvent * @since 3.0 */ public void setFocus() { - if (isValid(fProposalShell)) + if (isValid(fProposalShell)) { fProposalShell.setFocus(); + } } } diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/ContentAssistMessages.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/ContentAssistMessages.java index 5b89cba3c73..0b3a8846cbe 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/ContentAssistMessages.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/ContentAssistMessages.java @@ -78,8 +78,9 @@ public static String getFormattedString(String key, Object arg) { } catch (MissingResourceException e) { return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$ } - if (arg == null) + if (arg == null) { arg= ""; //$NON-NLS-1$ + } return MessageFormat.format(format, arg); } } diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/ContentAssistant2.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/ContentAssistant2.java index 8fbda719750..81a8dfbcb46 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/ContentAssistant2.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/ContentAssistant2.java @@ -121,8 +121,9 @@ protected void install() { protected void uninstall() { Shell shell= fShell; fShell= null; - if (isValid(shell)) + if (isValid(shell)) { shell.removeControlListener(this); + } Control w= fViewer.getTextWidget(); if (isValid(w)) { @@ -175,8 +176,9 @@ public void focusLost(FocusEvent e) { Display d= control.getDisplay(); if (d != null) { d.asyncExec(() -> { - if (!hasFocus()) + if (!hasFocus()) { hide(); + } }); } } @@ -196,8 +198,9 @@ public void widgetDisposed(DisposeEvent e) { @Override public void viewportChanged(int topIndex) { - if (System.currentTimeMillis() > fViewportListenerStartTime) + if (System.currentTimeMillis() > fViewportListenerStartTime) { hide(); + } } } @@ -234,8 +237,9 @@ public void run() { try { while (true) { synchronized (fMutex) { - if (fAutoActivationDelay != 0) + if (fAutoActivationDelay != 0) { fMutex.wait(fAutoActivationDelay); + } if (fIsReset) { fIsReset= false; continue; @@ -259,18 +263,21 @@ protected void reset(int showStyle) { protected void stop() { Thread threadToStop= fThread; - if (threadToStop != null) + if (threadToStop != null) { threadToStop.interrupt(); + } } @Override public void verifyKey(VerifyEvent e) { // Only act on typed characters and ignore modifier-only events - if (e.character == 0 && (e.keyCode & SWT.KEYCODE_BIT) == 0) + if (e.character == 0 && (e.keyCode & SWT.KEYCODE_BIT) == 0) { return; + } - if (e.character != 0 && (e.stateMask == SWT.ALT)) + if (e.character != 0 && (e.stateMask == SWT.ALT)) { return; + } @@ -285,22 +292,24 @@ public void verifyKey(VerifyEvent e) { - if (p.isCompletionProposalAutoActivation(e.character, fViewer, pos) && !fProposalPopup.isActive()) + if (p.isCompletionProposalAutoActivation(e.character, fViewer, pos) && !fProposalPopup.isActive()) { showStyle= SHOW_PROPOSALS; - else { - if (p.isContextInformationAutoActivation(e.character, fViewer, pos) && !fContextInfoPopup.isActive()) + } else { + if (p.isContextInformationAutoActivation(e.character, fViewer, pos) && !fContextInfoPopup.isActive()) { showStyle= SHOW_CONTEXT_INFO; - else { - if (fThread != null && fThread.isAlive()) + } else { + if (fThread != null && fThread.isAlive()) { stop(); + } return; } } - if (fThread != null && fThread.isAlive()) + if (fThread != null && fThread.isAlive()) { reset(showStyle); - else + } else { start(showStyle); + } } protected void showAssist(final int showStyle) { @@ -309,10 +318,11 @@ protected void showAssist(final int showStyle) { if (d != null) { try { d.syncExec(() -> { - if (showStyle == SHOW_PROPOSALS) + if (showStyle == SHOW_PROPOSALS) { fProposalPopup.showProposals(true); - else if (showStyle == SHOW_CONTEXT_INFO) + } else if (showStyle == SHOW_CONTEXT_INFO) { fContextInfoPopup.showContextProposals(true); + } }); } catch (SWTError e) { } @@ -345,15 +355,17 @@ protected void add(Object popup, Shell shell, int type, int offset) { checkType(type); if (fShells[type] != shell) { - if (fShells[type] != null) + if (fShells[type] != null) { fShells[type].removeListener(SWT.Dispose, this); + } shell.addListener(SWT.Dispose, this); fShells[type]= shell; } fPopups[type]= popup; - if (type == LAYOUT_CONTEXT_SELECTOR || type == LAYOUT_CONTEXT_INFO_POPUP) + if (type == LAYOUT_CONTEXT_SELECTOR || type == LAYOUT_CONTEXT_INFO_POPUP) { fContextType= type; + } layout(type, offset); adjustListeners(type); @@ -384,8 +396,9 @@ public void handleEvent(Event event) { case LAYOUT_CONTEXT_SELECTOR: if (isValid(fShells[LAYOUT_PROPOSAL_SELECTOR])) { - if (fProposalPopupOrientation == PROPOSAL_STACKED) + if (fProposalPopupOrientation == PROPOSAL_STACKED) { layout(LAYOUT_PROPOSAL_SELECTOR, getSelectionOffset()); + } // Restore event notification to the proposal popup. addContentAssistListener((IContentAssistListener2) fPopups[LAYOUT_PROPOSAL_SELECTOR], PROPOSAL_SELECTOR); } @@ -394,8 +407,9 @@ public void handleEvent(Event event) { case LAYOUT_CONTEXT_INFO_POPUP: if (isValid(fShells[LAYOUT_PROPOSAL_SELECTOR])) { - if (fContextInfoPopupOrientation == CONTEXT_INFO_BELOW) + if (fContextInfoPopupOrientation == CONTEXT_INFO_BELOW) { layout(LAYOUT_PROPOSAL_SELECTOR, getSelectionOffset()); + } } fContextType= LAYOUT_CONTEXT_SELECTOR; break; @@ -404,8 +418,9 @@ public void handleEvent(Event event) { protected int getShellType(Widget shell) { for (int i=0; i displayBounds.width) + if (location.x + shellBounds.width > displayBounds.width) { location.x= displayBounds.width - shellBounds.width; + } - if (location.x < displayBounds.x) + if (location.x < displayBounds.x) { location.x= displayBounds.x; + } } protected void shiftVerticalLocation(Point location, Rectangle shellBounds, Rectangle displayBounds) { - if (location.y + shellBounds.height > displayBounds.height) + if (location.y + shellBounds.height > displayBounds.height) { location.y= displayBounds.height - shellBounds.height; + } - if (location.y < displayBounds.y) + if (location.y < displayBounds.y) { location.y= displayBounds.y; + } } protected Point getAboveLocation(Shell shell, int offset) { @@ -549,8 +568,12 @@ protected Point getAboveLocation(Shell shell, int offset) { protected Point getBelowLocation(Shell shell, int offset) { StyledText text= fViewer.getTextWidget(); Point location= text.getLocationAtOffset(offset); - if (location.x < 0) location.x= 0; - if (location.y < 0) location.y= 0; + if (location.x < 0) { + location.x= 0; + } + if (location.y < 0) { + location.y= 0; + } location= text.toDisplay(location); Rectangle shellBounds= shell.getBounds(); @@ -583,14 +606,16 @@ protected void adjustListeners(int type) { switch (type) { case LAYOUT_PROPOSAL_SELECTOR: if (fContextType == LAYOUT_CONTEXT_SELECTOR && - isValid(fShells[LAYOUT_CONTEXT_SELECTOR])) + isValid(fShells[LAYOUT_CONTEXT_SELECTOR])) { // Disable event notification to the tip selector. removeContentAssistListener((IContentAssistListener2) fPopups[LAYOUT_CONTEXT_SELECTOR], CONTEXT_SELECTOR); + } break; case LAYOUT_CONTEXT_SELECTOR: - if (isValid(fShells[LAYOUT_PROPOSAL_SELECTOR])) + if (isValid(fShells[LAYOUT_PROPOSAL_SELECTOR])) { // Disable event notification to the proposal selector. removeContentAssistListener((IContentAssistListener2) fPopups[LAYOUT_PROPOSAL_SELECTOR], PROPOSAL_SELECTOR); + } break; case LAYOUT_CONTEXT_INFO_POPUP: break; @@ -635,8 +660,9 @@ public void processEvent(VerifyEvent event) { for (IContentAssistListener2 listener : listeners) { if (listener != null) { listener.processEvent(event); - if (!event.doit) + if (!event.doit) { return; + } } } } @@ -756,13 +782,15 @@ public void setContentAssistProcessor(IContentAssistProcessor processor, String Assert.isNotNull(contentType); - if (fProcessors == null) + if (fProcessors == null) { fProcessors= new HashMap<>(); + } - if (processor == null) + if (processor == null) { fProcessors.remove(contentType); - else + } else { fProcessors.put(contentType, processor); + } } /* @@ -770,8 +798,9 @@ public void setContentAssistProcessor(IContentAssistProcessor processor, String */ @Override public IContentAssistProcessor getContentAssistProcessor(String contentType) { - if (fProcessors == null) + if (fProcessors == null) { return null; + } return fProcessors.get(contentType); } @@ -826,8 +855,9 @@ private void manageAutoActivation(boolean start) { extension.appendVerifyKeyListener(fAutoAssistListener); } else { StyledText textWidget= fViewer.getTextWidget(); - if (isValid(textWidget)) + if (isValid(textWidget)) { textWidget.addVerifyKeyListener(fAutoAssistListener); + } } } @@ -837,8 +867,9 @@ private void manageAutoActivation(boolean start) { extension.removeVerifyKeyListener(fAutoAssistListener); } else { StyledText textWidget= fViewer.getTextWidget(); - if (isValid(textWidget)) + if (isValid(textWidget)) { textWidget.removeVerifyKeyListener(fAutoAssistListener); + } } fAutoAssistListener= null; @@ -999,8 +1030,9 @@ public void install(ITextViewer textViewer) { fInternalListener= new InternalListener(); AdditionalInfoController2 controller= null; - if (fInformationControlCreator != null) + if (fInformationControlCreator != null) { controller= new AdditionalInfoController2(fInformationControlCreator, OpenStrategy.getPostSelectionDelay()); + } fContextInfoPopup= new ContextInformationPopup2(this, fViewer); fProposalPopup= new CompletionProposalPopup2(this, fViewer, controller); @@ -1014,11 +1046,13 @@ public void install(ITextViewer textViewer) { @Override public void uninstall() { - if (fProposalPopup != null) + if (fProposalPopup != null) { fProposalPopup.hide(); + } - if (fContextInfoPopup != null) + if (fContextInfoPopup != null) { fContextInfoPopup.hide(); + } manageAutoActivation(false); @@ -1231,8 +1265,9 @@ private void uninstallKeyListener() { private int getNumberOfListeners() { int count= 0; for (int i= 0; i <= CONTEXT_INFO_POPUP; i++) { - if (fListeners[i] != null) + if (fListeners[i] != null) { ++ count; + } } return count; } @@ -1249,18 +1284,21 @@ public String showPossibleCompletions() { * Hides the proposal popup. */ public void hidePossibleCompletions() { - if (fProposalPopup != null) + if (fProposalPopup != null) { fProposalPopup.hide(); + } } /** * Hides any open pop-ups. */ protected void hide() { - if (fProposalPopup != null) + if (fProposalPopup != null) { fProposalPopup.hide(); - if (fContextInfoPopup != null) + } + if (fContextInfoPopup != null) { fContextInfoPopup.hide(); + } } /** @@ -1343,7 +1381,9 @@ ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int positio result[i]= new CompletionProposal(fProposalStrings[i], position, fProposalStrings[i].length(), fProposalStrings[i].length()); } return result; - } else return null; + } else { + return null; + } } /** @@ -1400,8 +1440,9 @@ IContextInformationValidator getContextInformationValidator(ITextViewer textView */ IContextInformationPresenter getContextInformationPresenter(ITextViewer textViewer, int offset) { IContextInformationValidator validator= getContextInformationValidator(textViewer, offset); - if (validator instanceof IContextInformationPresenter) + if (validator instanceof IContextInformationPresenter) { return (IContextInformationPresenter) validator; + } return null; } diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/ContextInformationPopup2.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/ContextInformationPopup2.java index 007a6df1303..d914a398cbd 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/ContextInformationPopup2.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/ContextInformationPopup2.java @@ -165,7 +165,9 @@ private void internalShowContextInfo(IContextInformation information, int offset ContextFrame current= new ContextFrame(); current.fInformation= information; current.fBeginOffset= (information instanceof IContextInformationExtension i) ? i.getContextInformationPosition() : offset; - if (current.fBeginOffset == -1) current.fBeginOffset= offset; + if (current.fBeginOffset == -1) { + current.fBeginOffset= offset; + } current.fOffset= offset; current.fVisibleOffset= fViewer.getTextWidget().getSelectionRange().x - (offset - current.fBeginOffset); current.fValidator= validator; @@ -189,8 +191,9 @@ private void internalShowContextFrame(ContextFrame frame, boolean initial) { frame.fValidator.install(frame.fInformation, fViewer, frame.fOffset); if (frame.fPresenter != null) { - if (fTextPresentation == null) + if (fTextPresentation == null) { fTextPresentation= new TextPresentation(); + } frame.fPresenter.install(frame.fInformation, fViewer, frame.fBeginOffset); frame.fPresenter.updatePresentation(frame.fOffset, fTextPresentation); } @@ -198,8 +201,9 @@ private void internalShowContextFrame(ContextFrame frame, boolean initial) { createContextInfoPopup(); fContextInfoText.setText(frame.fInformation.getInformationDisplayString()); - if (fTextPresentation != null) + if (fTextPresentation != null) { TextPresentation.applyTextPresentation(fTextPresentation, fContextInfoText); + } resize(); if (initial) { @@ -236,8 +240,9 @@ private String getErrorMessage() { * Creates the context information popup. This is the tooltip like overlay window. */ private void createContextInfoPopup() { - if (isValid(fContextInfoPopup)) + if (isValid(fContextInfoPopup)) { return; + } Control control= fViewer.getTextWidget(); Display display= control.getDisplay(); @@ -248,13 +253,15 @@ private void createContextInfoPopup() { fContextInfoText= new StyledText(fContextInfoPopup, SWT.MULTI | SWT.READ_ONLY); Color c= fContentAssistant.getContextInformationPopupBackground(); - if (c == null) + if (c == null) { c= display.getSystemColor(SWT.COLOR_INFO_BACKGROUND); + } fContextInfoText.setBackground(c); c= fContentAssistant.getContextInformationPopupForeground(); - if (c == null) + if (c == null) { c= display.getSystemColor(SWT.COLOR_INFO_FOREGROUND); + } fContextInfoText.setForeground(c); } @@ -303,8 +310,9 @@ private void hideContextInfoPopup() { } } - if (fContextInfoPopup == null) + if (fContextInfoPopup == null) { fContentAssistant.contextInformationClosed(); + } } /** @@ -312,8 +320,9 @@ private void hideContextInfoPopup() { * at a given offset. */ private void createContextSelector() { - if (isValid(fContextSelectorShell)) + if (isValid(fContextSelectorShell)) { return; + } Control control= fViewer.getTextWidget(); fContextSelectorShell= new Shell(control.getShell(), SWT.NO_TRIM | SWT.ON_TOP); @@ -334,13 +343,15 @@ private void createContextSelector() { fContextSelectorShell.pack(true); Color c= fContentAssistant.getContextSelectorBackground(); - if (c == null) + if (c == null) { c= control.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND); + } fContextSelectorTable.setBackground(c); c= fContentAssistant.getContextSelectorForeground(); - if (c == null) + if (c == null) { c= control.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND); + } fContextSelectorTable.setForeground(c); fContextSelectorTable.addSelectionListener(new SelectionListener() { @@ -368,8 +379,9 @@ public void widgetDefaultSelected(SelectionEvent e) { private void insertSelectedContext() { int i= fContextSelectorTable.getSelectionIndex(); - if (i < 0 || i >= fContextSelectorInput.length) + if (i < 0 || i >= fContextSelectorInput.length) { return; + } int position= fViewer.getSelectedRange().x; internalShowContextInfo(fContextSelectorInput[i], position); @@ -393,8 +405,9 @@ private void setContexts(IContextInformation[] contexts) { for (IContextInformation context : contexts) { t= context; item= new TableItem(fContextSelectorTable, SWT.NULL); - if (t.getImage() != null) + if (t.getImage() != null) { item.setImage(t.getImage()); + } item.setText(t.getContextDisplayString()); } @@ -407,8 +420,9 @@ private void setContexts(IContextInformation[] contexts) { * Displays the context selector. */ private void displayContextSelector() { - if (fContentAssistant.addContentAssistListener(this, ContentAssistant2.CONTEXT_SELECTOR)) + if (fContentAssistant.addContentAssistListener(this, ContentAssistant2.CONTEXT_SELECTOR)) { fContextSelectorShell.setVisible(true); + } } /** @@ -424,8 +438,9 @@ private void hideContextSelector() { fContextSelectorShell= null; } - if (!isValid(fContextInfoPopup)) + if (!isValid(fContextInfoPopup)) { fContentAssistant.contextInformationClosed(); + } } /** @@ -434,8 +449,9 @@ private void hideContextSelector() { * @return true if teh context selector has the focus */ public boolean hasFocus() { - if (isValid(fContextSelectorShell)) + if (isValid(fContextSelectorShell)) { return (fContextSelectorShell.isFocusControl() || fContextSelectorTable.isFocusControl()); + } return false; } @@ -460,10 +476,12 @@ public boolean isActive() { @Override public boolean verifyKey(VerifyEvent e) { - if (isValid(fContextSelectorShell)) + if (isValid(fContextSelectorShell)) { return contextSelectorKeyPressed(e); - if (isValid(fContextInfoPopup)) + } + if (isValid(fContextInfoPopup)) { return contextInfoPopupKeyPressed(e); + } return true; } @@ -494,14 +512,16 @@ private boolean contextSelectorKeyPressed(VerifyEvent e) { case SWT.PAGE_DOWN : change= visibleRows; - if (selection + change >= fContextSelectorTable.getItemCount()) + if (selection + change >= fContextSelectorTable.getItemCount()) { change= fContextSelectorTable.getItemCount() - selection; + } break; case SWT.PAGE_UP : change= -visibleRows; - if (selection + change < 0) + if (selection + change < 0) { change= -selection; + } break; case SWT.HOME : @@ -513,8 +533,9 @@ private boolean contextSelectorKeyPressed(VerifyEvent e) { break; default: - if (e.keyCode != SWT.MOD1 && e.keyCode != SWT.MOD2 && e.keyCode != SWT.MOD3 && e.keyCode != SWT.MOD4) + if (e.keyCode != SWT.MOD1 && e.keyCode != SWT.MOD2 && e.keyCode != SWT.MOD3 && e.keyCode != SWT.MOD4) { hideContextSelector(); + } return true; } @@ -555,8 +576,9 @@ private boolean contextInfoPopupKeyPressed(KeyEvent e) { validateContextInformation(); break; default: - if (e.keyCode != SWT.MOD1 && e.keyCode != SWT.MOD2 && e.keyCode != SWT.MOD3 && e.keyCode != SWT.MOD4) + if (e.keyCode != SWT.MOD1 && e.keyCode != SWT.MOD2 && e.keyCode != SWT.MOD3 && e.keyCode != SWT.MOD4) { hideContextInfoPopup(); + } break; } @@ -571,10 +593,12 @@ private boolean contextInfoPopupKeyPressed(KeyEvent e) { @Override public void processEvent(VerifyEvent event) { - if (isValid(fContextSelectorShell)) + if (isValid(fContextSelectorShell)) { contextSelectorProcessEvent(event); - if (isValid(fContextInfoPopup)) + } + if (isValid(fContextInfoPopup)) { contextInfoPopupProcessEvent(event); + } } /** @@ -598,8 +622,9 @@ private void contextSelectorProcessEvent(VerifyEvent e) { * @param e the verify event describing the key stroke */ private void contextInfoPopupProcessEvent(VerifyEvent e) { - if (e.start != e.end && (e.text == null || e.text.isEmpty())) + if (e.start != e.end && (e.text == null || e.text.isEmpty())) { validateContextInformation(); + } } /** diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/PopupCloser2.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/PopupCloser2.java index f3e9794cbbc..af381b1c33e 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/PopupCloser2.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/PopupCloser2.java @@ -65,8 +65,9 @@ public void install(ContentAssistant2 contentAssistant, Table table) { } fTable.addFocusListener(this); fScrollbar= fTable.getVerticalBar(); - if (fScrollbar != null) + if (fScrollbar != null) { fScrollbar.addSelectionListener(this); + } } } @@ -75,13 +76,16 @@ public void install(ContentAssistant2 contentAssistant, Table table) { */ public void uninstall() { fContentAssistant= null; - if (isValid(fShell)) + if (isValid(fShell)) { fShell.removeShellListener(this); + } fShell= null; - if (isValid(fScrollbar)) + if (isValid(fScrollbar)) { fScrollbar.removeSelectionListener(this); - if (isValid(fTable)) + } + if (isValid(fTable)) { fTable.removeFocusListener(this); + } } @Override @@ -103,21 +107,24 @@ public void focusLost(final FocusEvent e) { fScrollbarClicked= false; Display d= fTable.getDisplay(); d.asyncExec(() -> { - if (isValid(fTable) && !fTable.isFocusControl() && !fScrollbarClicked && fContentAssistant != null) + if (isValid(fTable) && !fTable.isFocusControl() && !fScrollbarClicked && fContentAssistant != null) { fContentAssistant.popupFocusLost(e); + } }); } @Override public void shellDeactivated(ShellEvent e) { - if (fContentAssistant != null) + if (fContentAssistant != null) { fContentAssistant.hide(); + } } @Override public void shellClosed(ShellEvent e) { - if (fContentAssistant != null) + if (fContentAssistant != null) { fContentAssistant.hide(); + } } } diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/ChangeRegion.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/ChangeRegion.java index e4138f04b2b..6542155766d 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/ChangeRegion.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/ChangeRegion.java @@ -84,8 +84,9 @@ public List getAdjustedRanges() { * @return the line coverage of the adjusted ranges */ public ILineRange getAdjustedCoverage() { - if (fAdjusted.isEmpty()) + if (fAdjusted.isEmpty()) { return new LineRange(fLines.getStartLine(), 0); + } Range first= fAdjusted.get(0); Range last= fAdjusted.get(fAdjusted.size() - 1); @@ -113,8 +114,9 @@ public void adjustTo(Hunk hunk) { // do we need a split? int unchanged= getUnchanged(hunk, range.start()); if (unchanged > 0) { - if (unchanged >= range.length()) + if (unchanged >= range.length()) { continue; + } range= range.split(unchanged); it.add(range); it.previous(); it.next(); // needed so we can remove below @@ -148,8 +150,9 @@ private int getOverlap(Hunk hunk, int line) { int deltaLine= hunk.line + hunk.changed; if (hunk.delta >= 0) { - if (deltaLine <= line) + if (deltaLine <= line) { return 0; + } return deltaLine - line; } diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/Colors.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/Colors.java index f09807e32a4..ccfc989bfaa 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/Colors.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/Colors.java @@ -91,7 +91,9 @@ private static float[] toHSI(RGB color) { } } hue *= 60; - if (hue < 0) hue += 360; + if (hue < 0) { + hue += 360; + } } return new float[] {hue, saturation, intensity}; } @@ -112,7 +114,9 @@ private static RGB fromHSI(float[] hsi) { } else { float temp2= intensity < 0.5f ? intensity * (1.0f + saturation) : (intensity + saturation) - (intensity * saturation); float temp1= 2f * intensity - temp2; - if (hue == 360) hue = 0; + if (hue == 360) { + hue = 0; + } hue /= 360; r= hue2RGB(temp1, temp2, hue + 1f/3f); @@ -127,16 +131,20 @@ private static RGB fromHSI(float[] hsi) { } private static float hue2RGB(float t1, float t2, float hue) { - if (hue < 0) + if (hue < 0) { hue += 1; - else if (hue > 1) + } else if (hue > 1) { hue -= 1; - if (6f * hue < 1) + } + if (6f * hue < 1) { return t1 +(t2 - t1) * 6f * hue; - if (2f * hue < 1) + } + if (2f * hue < 1) { return t2; - if (3f * hue < 2) + } + if (3f * hue < 2) { return t1 + (t2 - t1) * (2f/3f - hue) * 6f; + } return t1; } @@ -180,13 +188,15 @@ public static RGB[] palette(RGB start, RGB end, int steps) { Assert.isLegal(end != null); Assert.isLegal(steps > 0); - if (steps == 1) + if (steps == 1) { return new RGB[] { start }; + } float step= 1.0f / (steps - 1); RGB[] gradient= new RGB[steps]; - for (int i= 0; i < steps; i++) + for (int i= 0; i < steps; i++) { gradient[i]= blend(start, end, step * i); + } return gradient; } @@ -215,8 +225,9 @@ public static RGB[] rainbow(int steps) { Assert.isLegal(steps >= 2); RGB[] rainbow= new RGB[steps]; - for (int i= 0; i < steps; i++) + for (int i= 0; i < steps; i++) { rainbow[i]= new RGB(computeHue(i), 1f, 1f); + } return rainbow; } diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/Hunk.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/Hunk.java index ad99a793f9f..235801046b2 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/Hunk.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/Hunk.java @@ -65,8 +65,9 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (obj == this) + if (obj == this) { return true; + } if (obj instanceof Hunk other) { return other.line == this.line && other.delta == this.delta && other.changed == this.changed; } diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/HunkComputer.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/HunkComputer.java index bc4c74e1352..6d330e95b22 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/HunkComputer.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/HunkComputer.java @@ -42,8 +42,9 @@ public static Hunk[] computeHunks(ILineDiffer differ, int lines) { ILineDiffInfo info= null; for (int line= 0; line < lines; line++) { info= differ.getLineInfo(line); - if (info == null) + if (info == null) { continue; + } int changeType= info.getChangeType(); switch (changeType) { diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/Range.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/Range.java index 22158d26efb..f1483e3b4f4 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/Range.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/Range.java @@ -133,8 +133,9 @@ public int end() { * @throws LineIndexOutOfBoundsException if start < 0 */ public void moveTo(int start) throws LineIndexOutOfBoundsException { - if ((start < 0)) + if ((start < 0)) { throw new LineIndexOutOfBoundsException("Cannot set a negative start: " + start); //$NON-NLS-1$ + } fStart= start; } @@ -168,8 +169,9 @@ public void moveBy(int delta) throws LineIndexOutOfBoundsException { */ public void setStart(int start) throws LineIndexOutOfBoundsException { int end= end(); - if (((start < 0) || (start >= end))) + if (((start < 0) || (start >= end))) { throw new LineIndexOutOfBoundsException("Cannot set a negative start: " + start); //$NON-NLS-1$ + } moveTo(start); setEnd(end); } @@ -191,8 +193,9 @@ public void setEnd(int end) throws LineIndexOutOfBoundsException { * @throws LineIndexOutOfBoundsException if length <= 0 */ public void setLength(int length) throws LineIndexOutOfBoundsException { - if ((length <= 0)) + if ((length <= 0)) { throw new LineIndexOutOfBoundsException("Cannot set length <= 0: " + length); //$NON-NLS-1$ + } fLength= length; } @@ -235,8 +238,9 @@ public void resizeAndMoveBy(int delta) throws LineIndexOutOfBoundsException { * @throws LineIndexOutOfBoundsException if remaining>= {@link #length()} or remaining<= 0 */ public Range split(int remaining) throws LineIndexOutOfBoundsException { - if ((remaining >= length())) // assert before modification + if ((remaining >= length())) { // assert before modification throw new LineIndexOutOfBoundsException("Remaining must be less than length: " + length()); //$NON-NLS-1$ + } int splitLength= length() - remaining; setLength(remaining); @@ -250,10 +254,12 @@ public Range split(int remaining) throws LineIndexOutOfBoundsException { * @return true if range has the same offset and length as the receiver */ public boolean equalRange(ILineRange range) { - if (range == this) + if (range == this) { return true; - if (range == null) + } + if (range == null) { return false; + } return range.getStartLine() == start() && range.getNumberOfLines() == length(); } diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/RevisionPainter.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/RevisionPainter.java index 99870496d46..a001961a37c 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/RevisionPainter.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/RevisionPainter.java @@ -167,8 +167,9 @@ public void setInfo(RevisionInformation info) { fFocusColors.clear(); fGradientStart= null; fGradientStop= null; - if (info == null) + if (info == null) { return; + } List revisions= new ArrayList<>(); for (Revision revision : info.getRevisions()) { revisions.add(Long.valueOf(computeAge(revision))); @@ -212,10 +213,11 @@ private RGB adaptColor(Revision revision, boolean focus) { int size= fRevisions.size(); // relative age: newest is 0, oldest is 1 // if there is only one revision, use an intermediate value to avoid extreme coloring - if (index == -1 || size < 2) + if (index == -1 || size < 2) { scale= 0.5f; - else + } else { scale= (float) index / (size - 1); + } } else { Assert.isTrue(false); return null; // dummy @@ -269,8 +271,9 @@ private long computeAge(Revision revision) { public RGB getColor(Revision revision, boolean focus) { Map map= focus ? fFocusColors : fColors; RGB color= map.get(revision); - if (color != null) + if (color != null) { return color; + } color= adaptColor(revision, focus); map.put(revision, color); @@ -293,16 +296,18 @@ private void handleMouseUp(Event e) { if (upRegion == downRegion) { Revision revision= upRegion == null ? null : upRegion.getRevision(); - if (revision == fSelectedRevision) + if (revision == fSelectedRevision) { revision= null; // deselect already selected revision + } handleRevisionSelected(revision); } } } private void handleMouseDown(Event e) { - if (e.button == 3) + if (e.button == 3) { updateFocusRevision(null); // kill any focus as the ctx menu is going to show + } if (e.button == 1) { fMouseDownRegion= fFocusRange; postRedraw(); @@ -393,9 +398,10 @@ public void setInformation(String content) { */ private String addCSSToHTMLFragment(String html) { int max= Math.min(100, html.length()); - if (html.substring(0, max).contains("")) //$NON-NLS-1$ + if (html.substring(0, max).contains("")) { //$NON-NLS-1$ // there is already a header return html; + } StringBuilder info= new StringBuilder(512 + html.length()); HTMLPrinter.insertPageProlog(info, 0, fgStyleSheet); @@ -464,8 +470,9 @@ public IInformationControlCreator getHoverControlCreator() { RevisionInformation revisionInfo= fRevisionInfo; if (revisionInfo != null) { IInformationControlCreator creator= revisionInfo.getHoverControlCreator(); - if (creator != null) + if (creator != null) { return creator; + } } return new HoverInformationControlCreator(false); } @@ -498,8 +505,9 @@ public IInformationControlCreator getInformationPresenterControlCreator() { RevisionInformation revisionInfo= fRevisionInfo; if (revisionInfo != null) { IInformationControlCreator creator= revisionInfo.getInformationPresenterControlCreator(); - if (creator != null) + if (creator != null) { return creator; + } } return new HoverInformationControlCreator(true); } @@ -718,8 +726,9 @@ public void setParentRuler(CompositeRuler parentRuler) { */ public void paint(GC gc, ILineRange visibleLines) { connectIfNeeded(); - if (!isConnected()) + if (!isConnected()) { return; + } // compute the horizontal indent of the author for the case that we show revision // and author @@ -752,20 +761,24 @@ public void paint(GC gc, ILineRange visibleLines) { * visible. */ private void connectIfNeeded() { - if (isConnected() || fParentRuler == null) + if (isConnected() || fParentRuler == null) { return; + } fViewer= fParentRuler.getTextViewer(); - if (fViewer == null) + if (fViewer == null) { return; + } fWidget= fViewer.getTextWidget(); - if (fWidget == null) + if (fWidget == null) { return; + } fControl= fColumn.getControl(); - if (fControl == null) + if (fControl == null) { return; + } fControl.addMouseTrackListener(fMouseHandler); fControl.addMouseMoveListener(fMouseHandler); @@ -793,10 +806,11 @@ private boolean isConnected() { */ public void setModel(IAnnotationModel model) { IAnnotationModel diffModel; - if (model instanceof IAnnotationModelExtension) + if (model instanceof IAnnotationModelExtension) { diffModel= ((IAnnotationModelExtension) model).getAnnotationModel(IChangeRulerColumn.QUICK_DIFF_MODEL_ID); - else + } else { diffModel= model; + } setDiffer(diffModel); setAnnotationModel(model); @@ -808,8 +822,9 @@ public void setModel(IAnnotationModel model) { * @param model the annotation model. */ private void setAnnotationModel(IAnnotationModel model) { - if (fAnnotationModel != model) + if (fAnnotationModel != model) { fAnnotationModel= model; + } } /** @@ -820,11 +835,13 @@ private void setAnnotationModel(IAnnotationModel model) { private void setDiffer(IAnnotationModel differ) { if (differ instanceof ILineDiffer || differ == null) { if (fLineDiffer != differ) { - if (fLineDiffer != null) + if (fLineDiffer != null) { ((IAnnotationModel) fLineDiffer).removeAnnotationModelListener(fAnnotationListener); + } fLineDiffer= (ILineDiffer) differ; - if (fLineDiffer != null) + if (fLineDiffer != null) { ((IAnnotationModel) fLineDiffer).addAnnotationModelListener(fAnnotationListener); + } } } } @@ -851,8 +868,9 @@ private void handleDispose() { */ private void paintRange(RevisionRange range, GC gc) { ILineRange widgetRange= modelLinesToWidgetLines(range); - if (widgetRange == null) + if (widgetRange == null) { return; + } Revision revision= range.getRevision(); boolean drawArmedFocus= range == fMouseHandler.fMouseDownRegion; @@ -907,8 +925,9 @@ private void paintRange(RevisionRange range, GC gc) { * @since 3.3 */ private int getBaselineBias(GC gc, int widgetLine) { - if (widgetLine == fWidget.getLineCount()) + if (widgetLine == fWidget.getLineCount()) { widgetLine--; + } /* * https://bugs.eclipse.org/bugs/show_bug.cgi?id=62951 @@ -946,18 +965,21 @@ private Color lookupColor(Revision revision, boolean focus) { private RevisionRange getRange(int line) { List ranges= getRangeCache(); - if (ranges.isEmpty() || line == -1) + if (ranges.isEmpty() || line == -1) { return null; + } for (RevisionRange range : ranges) { - if (contains(range, line)) + if (contains(range, line)) { return range; + } } // line may be right after the last region RevisionRange lastRegion= ranges.get(ranges.size() - 1); - if (line == end(lastRegion)) + if (line == end(lastRegion)) { return lastRegion; + } return null; } @@ -976,17 +998,20 @@ private List getRanges(ILineRange lines) { for (int i= 0; i < ranges.size(); i++) { RevisionRange range= ranges.get(i); int rangeEnd= end(range); - if (first == -1 && rangeEnd > lines.getStartLine()) + if (first == -1 && rangeEnd > lines.getStartLine()) { first= i; + } if (first != -1 && rangeEnd > end) { last= i; break; } } - if (first == -1) + if (first == -1) { return Collections.emptyList(); - if (last == -1) + } + if (last == -1) { last= ranges.size() - 1; // bottom index may be one too much + } return ranges.subList(first, last + 1); } @@ -1059,8 +1084,9 @@ private ILineRange modelLinesToWidgetLines(ILineRange range) { for (int modelLine= range.getStartLine(); modelLine < modelEndLine; modelLine++) { int widgetLine= extension.modelLine2WidgetLine(modelLine); if (widgetLine != -1) { - if (widgetStartLine == -1) + if (widgetStartLine == -1) { widgetStartLine= widgetLine; + } widgetEndLine= widgetLine; } } @@ -1076,8 +1102,9 @@ private ILineRange modelLinesToWidgetLines(ILineRange range) { // ignore and return null } } - if (widgetStartLine == -1 || widgetEndLine == -1) + if (widgetStartLine == -1 || widgetEndLine == -1) { return null; + } return new LineRange(widgetStartLine, widgetEndLine - widgetStartLine + 1); } @@ -1109,8 +1136,9 @@ private Rectangle computeBoxBounds(ILineRange range) { * Shows (or hides) the overview annotations. */ private void updateOverviewAnnotations() { - if (fAnnotationModel == null) + if (fAnnotationModel == null) { return; + } Revision revision= fFocusRevision != null ? fFocusRevision : fSelectedRevision; @@ -1142,8 +1170,9 @@ private void updateOverviewAnnotations() { } } fAnnotations.clear(); - if (added != null) + if (added != null) { fAnnotations.addAll(added.keySet()); + } } @@ -1159,10 +1188,11 @@ private IRegion toCharRegion(ILineRange lines) throws BadLocationException { int offset= document.getLineOffset(lines.getStartLine()); int nextLine= end(lines); int endOffset; - if (nextLine >= document.getNumberOfLines()) + if (nextLine >= document.getNumberOfLines()) { endOffset= document.getLength(); - else + } else { endOffset= document.getLineOffset(nextLine); + } return new Region(offset, endOffset - offset); } @@ -1175,8 +1205,9 @@ void handleRevisionSelected(Revision revision) { fSelectedRevision= revision; fRevisionSelectionProvider.revisionSelected(revision); - if (isConnected()) + if (isConnected()) { updateOverviewAnnotations(); + } postRedraw(); } @@ -1188,8 +1219,9 @@ void handleRevisionSelected(Revision revision) { */ void handleRevisionSelected(String id) { Assert.isLegal(id != null); - if (fRevisionInfo == null) + if (fRevisionInfo == null) { return; + } for (Revision revision : fRevisionInfo.getRevisions()) { if (id.equals(revision.getId())) { @@ -1217,8 +1249,9 @@ public RevisionSelectionProvider getRevisionSelectionProvider() { * @param line the new focus line, -1 for no focus */ private void updateFocusLine(int line) { - if (fFocusLine != line) + if (fFocusLine != line) { onFocusLineChanged(fFocusLine, line); + } } /** @@ -1228,8 +1261,9 @@ private void updateFocusLine(int line) { * @param nextLine the new focus line (-1 for no focus) */ private void onFocusLineChanged(int previousLine, int nextLine) { - if (DEBUG) + if (DEBUG) { System.out.println("line: " + previousLine + " > " + nextLine); //$NON-NLS-1$ //$NON-NLS-2$ + } fFocusLine= nextLine; RevisionRange region= getRange(nextLine); updateFocusRange(region); @@ -1241,8 +1275,9 @@ private void onFocusLineChanged(int previousLine, int nextLine) { * @param range the new focus range, null for no focus */ private void updateFocusRange(RevisionRange range) { - if (range != fFocusRange) + if (range != fFocusRange) { onFocusRangeChanged(fFocusRange, range); + } } /** @@ -1252,16 +1287,18 @@ private void updateFocusRange(RevisionRange range) { * @param nextRange the new focus range (null for no focus) */ private void onFocusRangeChanged(RevisionRange previousRange, RevisionRange nextRange) { - if (DEBUG) + if (DEBUG) { System.out.println("range: " + previousRange + " > " + nextRange); //$NON-NLS-1$ //$NON-NLS-2$ + } fFocusRange= nextRange; Revision revision= nextRange == null ? null : nextRange.getRevision(); updateFocusRevision(revision); } private void updateFocusRevision(Revision revision) { - if (fFocusRevision != revision) + if (fFocusRevision != revision) { onFocusRevisionChanged(fFocusRevision, revision); + } } /** @@ -1271,8 +1308,9 @@ private void updateFocusRevision(Revision revision) { * @param nextRevision the new focus revision (null for no focus) */ private void onFocusRevisionChanged(Revision previousRevision, Revision nextRevision) { - if (DEBUG) + if (DEBUG) { System.out.println("revision: " + previousRevision + " > " + nextRevision); //$NON-NLS-1$ //$NON-NLS-2$ + } fFocusRevision= nextRevision; uninstallWheelHandler(); installWheelHandler(); @@ -1329,8 +1367,9 @@ private void handleMouseWheel(Event event) { nextWidgetRange= last; break; } - if (widgetRange != null) + if (widgetRange != null) { last= widgetRange; + } } } else { for (ListIterator it= ranges.listIterator(ranges.size()); it.hasPrevious();) { @@ -1340,13 +1379,15 @@ private void handleMouseWheel(Event event) { nextWidgetRange= last; break; } - if (widgetRange != null) + if (widgetRange != null) { last= widgetRange; + } } } - if (nextWidgetRange == null) + if (nextWidgetRange == null) { return; + } int widgetCurrentFocusLine= modelLinesToWidgetLines(new LineRange(documentHoverLine, 1)).getStartLine(); int widgetNextFocusLine= nextWidgetRange.getStartLine(); @@ -1421,8 +1462,9 @@ private int getWidth() { * @return the System background color for list widgets */ private Color getBackground() { - if (fBackground == null) + if (fBackground == null) { return fWidget.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND); + } return fBackground; } @@ -1461,8 +1503,9 @@ Revision getRevision(int offset) { } if (line != -1) { RevisionRange range= getRange(line); - if (range != null) + if (range != null) { return range.getRevision(); + } } return null; } @@ -1492,12 +1535,13 @@ public int getRequiredWidth() { authorWidth= Math.max(authorWidth, revision.getAuthor().length()); } fRevisionIdChars= revisionWidth + 1; - if (fShowAuthor && fShowRevision) + if (fShowAuthor && fShowRevision) { fRequiredWidth= revisionWidth + authorWidth + 2; - else if (fShowAuthor) + } else if (fShowAuthor) { fRequiredWidth= authorWidth + 1; - else + } else { fRequiredWidth= revisionWidth + 1; + } } else { fRequiredWidth= 0; } @@ -1559,8 +1603,9 @@ public void removeRevisionListener(IRevisionListener listener) { * @since 3.3 */ private void informListeners() { - if (fRevisionInfo == null || fRevisionListeners.isEmpty()) + if (fRevisionInfo == null || fRevisionListeners.isEmpty()) { return; + } RevisionEvent event= new RevisionEvent(fRevisionInfo); for (IRevisionListener listener : fRevisionListeners) { diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/RevisionSelectionProvider.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/RevisionSelectionProvider.java index e5b1a299768..c34ee461dad 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/RevisionSelectionProvider.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/RevisionSelectionProvider.java @@ -113,23 +113,26 @@ public void removeSelectionChangedListener(ISelectionChangedListener listener) { @Override public ISelection getSelection() { - if (fSelection == null) + if (fSelection == null) { return StructuredSelection.EMPTY; + } return new StructuredSelection(fSelection); } @Override public void setSelection(ISelection selection) { - if (fIgnoreEvents) + if (fIgnoreEvents) { return; + } if (selection instanceof IStructuredSelection) { Object first= ((IStructuredSelection) selection).getFirstElement(); - if (first instanceof Revision) + if (first instanceof Revision) { fPainter.handleRevisionSelected((Revision) first); - else if (first instanceof String) + } else if (first instanceof String) { fPainter.handleRevisionSelected((String) first); - else if (selection.isEmpty()) + } else if (selection.isEmpty()) { fPainter.handleRevisionSelected((Revision) null); + } } } diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/source/DiffPainter.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/source/DiffPainter.java index 05b2e1476cd..d7f5bcca2fb 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/source/DiffPainter.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/source/DiffPainter.java @@ -148,8 +148,9 @@ public void setBackground(Color background) { */ public void paint(GC gc, ILineRange visibleModelLines) { connectIfNeeded(); - if (!isConnected()) + if (!isConnected()) { return; + } // draw diff info final int lastLine= end(visibleModelLines); @@ -165,20 +166,24 @@ public void paint(GC gc, ILineRange visibleModelLines) { * visible. */ private void connectIfNeeded() { - if (isConnected() || fParentRuler == null) + if (isConnected() || fParentRuler == null) { return; + } fViewer= fParentRuler.getTextViewer(); - if (fViewer == null) + if (fViewer == null) { return; + } fWidget= fViewer.getTextWidget(); - if (fWidget == null) + if (fWidget == null) { return; + } fControl= fColumn.getControl(); - if (fControl == null) + if (fControl == null) { return; + } fControl.addDisposeListener(e -> handleDispose()); fDisplay= fControl.getDisplay(); @@ -213,8 +218,9 @@ private void handleDispose() { */ private void paintLine(int line, GC gc, int width, Color deletionColor) { int widgetLine= JFaceTextUtil.modelLineToWidgetLine(fViewer, line); - if (widgetLine == -1) + if (widgetLine == -1) { return; + } ILineDiffInfo info= getDiffInfo(line); @@ -234,10 +240,12 @@ private void paintLine(int line, GC gc, int width, Color deletionColor) { if (delBefore > 0 || delBelow > 0) { gc.setForeground(deletionColor); gc.setLineWidth(1); - if (delBefore > 0) + if (delBefore > 0) { gc.drawLine(0, y, width, y); - if (delBelow > 0) + } + if (delBelow > 0) { gc.drawLine(0, y + lineHeight - 1, width, y + lineHeight - 1); + } } } } @@ -261,8 +269,9 @@ private boolean hasSpecialColor(ILineDiffInfo info) { * @return the ILineDiffInfo for line, or null. */ private ILineDiffInfo getDiffInfo(int line) { - if (fLineDiffer != null) + if (fLineDiffer != null) { return fLineDiffer.getLineInfo(line); + } return null; } @@ -303,21 +312,24 @@ private Color getColor(ILineDiffInfo info) { * @return the shaded color */ private Color getShadedColor(Color color) { - if (color == null) + if (color == null) { return null; + } - if (fSharedColors == null) + if (fSharedColors == null) { return color; + } RGB baseRGB= color.getRGB(); RGB background= getBackground().getRGB(); boolean darkBase= isDark(baseRGB); boolean darkBackground= isDark(background); - if (darkBase && darkBackground) + if (darkBase && darkBackground) { background= new RGB(255, 255, 255); - else if (!darkBase && !darkBackground) + } else if (!darkBase && !darkBackground) { background= new RGB(0, 0, 0); + } return fSharedColors.getColor(interpolate(baseRGB, background, 0.6)); } @@ -330,10 +342,11 @@ else if (!darkBase && !darkBackground) */ public void setModel(IAnnotationModel model) { IAnnotationModel newModel; - if (model instanceof IAnnotationModelExtension) + if (model instanceof IAnnotationModelExtension) { newModel= ((IAnnotationModelExtension) model).getAnnotationModel(IChangeRulerColumn.QUICK_DIFF_MODEL_ID); - else + } else { newModel= model; + } setDiffer(newModel); } @@ -346,8 +359,9 @@ public void setModel(IAnnotationModel model) { private void setDiffer(IAnnotationModel differ) { if (differ instanceof ILineDiffer) { if (fLineDiffer != differ) { - if (fLineDiffer != null) + if (fLineDiffer != null) { ((IAnnotationModel) fLineDiffer).removeAnnotationModelListener(fAnnotationListener); + } fLineDiffer= (ILineDiffer) differ; ((IAnnotationModel) fLineDiffer).addAnnotationModelListener(fAnnotationListener); } @@ -400,8 +414,9 @@ private static int end(ILineRange range) { * @return the System background color for list widgets */ private Color getBackground() { - if (fBackground == null) + if (fBackground == null) { return fWidget.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND); + } return fBackground; } @@ -463,8 +478,9 @@ public String getDisplayCharacter(int line) { * @return the character indication for info */ private String getDisplayCharacter(ILineDiffInfo info) { - if (info == null) + if (info == null) { return " "; //$NON-NLS-1$ + } switch (info.getChangeType()) { case ILineDiffInfo.CHANGED: return "~"; //$NON-NLS-1$ @@ -494,8 +510,9 @@ private static RGB interpolate(RGB fg, RGB bg, double scale) { * @return the grey-scale value */ private static double greyLevel(RGB rgb) { - if (rgb.red == rgb.green && rgb.green == rgb.blue) + if (rgb.red == rgb.green && rgb.green == rgb.blue) { return rgb.red; + } return (0.299 * rgb.red + 0.587 * rgb.green + 0.114 * rgb.blue + 0.5); } @@ -516,8 +533,9 @@ private static boolean isDark(RGB rgb) { * @since 3.3 */ public boolean hasInformation() { - if (fLineDiffer instanceof ILineDifferExtension2) + if (fLineDiffer instanceof ILineDifferExtension2) { return !((ILineDifferExtension2) fLineDiffer).isSuspended(); + } return fLineDiffer != null; }