diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/AdditionalInfoController.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/AdditionalInfoController.java index 4ffe8063a06..bbd3fbb39a5 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/AdditionalInfoController.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/AdditionalInfoController.java @@ -287,16 +287,19 @@ public synchronized final void reset(ICompletionProposal p) { long oldWakeup= fNextWakeup; Task task= taskOnReset(p); schedule(task, System.currentTimeMillis()); - if (fNextWakeup < oldWakeup) + if (fNextWakeup < oldWakeup) { notifyAll(); + } } } private Task taskOnReset(ICompletionProposal p) { - if (p == null) + if (p == null) { return IDLE; - if (isExt5(p)) + } + if (isExt5(p)) { return FIRST_WAIT; + } return LEGACY_WAIT; } @@ -325,10 +328,11 @@ private Task currentTask() { private void schedule(Task task, long current) { fTask= task; long nextWakeup= current + task.delay(); - if (nextWakeup <= current) + if (nextWakeup <= current) { fNextWakeup= Long.MAX_VALUE; - else + } else { fNextWakeup= nextWakeup; + } } private boolean isExt5(ICompletionProposal p) { @@ -473,8 +477,9 @@ public void install(Control control) { @Override protected void showInformation(ICompletionProposal proposal, Object info) { InformationControlReplacer replacer= getInternalAccessor().getInformationControlReplacer(); - if (replacer != null) + if (replacer != null) { replacer.hideInformationControl(); + } AdditionalInfoController.this.showInformation(proposal, info); } }; @@ -601,10 +606,12 @@ protected Point computeSizeConstraints(Control subjectControl, IInformationContr size.y -= shellTrim.height; } - 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/text/contentassist/AsyncCompletionProposalPopup.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/AsyncCompletionProposalPopup.java index 86b79ea32ce..cf2b0306323 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/AsyncCompletionProposalPopup.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/AsyncCompletionProposalPopup.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016 Red Hat Inc. and others. + * Copyright (c) 2016, 2025 Red Hat Inc. and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -159,8 +159,9 @@ public AsyncCompletionProposalPopup(ContentAssistant contentAssistant, ITextView */ @Override public String showProposals(boolean autoActivated) { - if (fKeyListener == null) + if (fKeyListener == null) { fKeyListener= new ProposalSelectionListener(); + } final Control control= fContentAssistSubjectControlAdapter.getControl(); @@ -304,11 +305,13 @@ public String incrementalComplete() { } final Control control= fContentAssistSubjectControlAdapter.getControl(); - if (fKeyListener == null) + if (fKeyListener == null) { fKeyListener= new ProposalSelectionListener(); + } - if (!isValid(fProposalShell) && !control.isDisposed()) + if (!isValid(fProposalShell) && !control.isDisposed()) { fContentAssistSubjectControlAdapter.addKeyListener(fKeyListener); + } fInvocationOffset= fContentAssistSubjectControlAdapter.getSelectedRange().x; fFilterOffset= fInvocationOffset; @@ -458,8 +461,9 @@ public void run() { try { while (true) { synchronized (fMutex) { - if (fAutoActivationDelay != 0) + if (fAutoActivationDelay != 0) { fMutex.wait(fAutoActivationDelay); + } } Optional display= Optional.ofNullable(fContentAssistSubjectControlAdapter.getControl()).map(Control::getDisplay); display.ifPresent(d -> d.asyncExec(() -> displayProposals(true))); @@ -472,8 +476,9 @@ public void run() { protected void stop() { Thread threadToStop= fThread; - if (threadToStop != null && threadToStop.isAlive()) + if (threadToStop != null && threadToStop.isAlive()) { threadToStop.interrupt(); + } } } diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposal.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposal.java index e9493849bc2..8dd85ff6f9c 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposal.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposal.java @@ -111,8 +111,9 @@ public Image getImage() { @Override public String getDisplayString() { - if (fDisplayString != null) + if (fDisplayString != null) { return fDisplayString; + } return fReplacementString; } diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposalPopup.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposalPopup.java index d87fe7aaee1..3333fe01085 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposalPopup.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposalPopup.java @@ -151,13 +151,15 @@ public Object execute(ExecutionEvent event) throws ExecutionException { switch (fOperationCode) { case SELECT_NEXT: selectionIndex+= 1; - if (selectionIndex > itemCount - 1) + if (selectionIndex > itemCount - 1) { selectionIndex= 0; + } break; case SELECT_PREVIOUS: selectionIndex-= 1; - if (selectionIndex < 0) + if (selectionIndex < 0) { selectionIndex= itemCount - 1; + } break; default: break; @@ -230,27 +232,31 @@ public int getContextInformationPosition() { final class ProposalSelectionListener implements 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); + } } } } @@ -264,16 +270,19 @@ private CommandKeyListener(KeySequence keySequence) { @Override public void keyPressed(KeyEvent e) { - if (!isValid(fProposalShell)) + if (!isValid(fProposalShell)) { return; + } int accelerator= SWTKeySupport.convertEventToUnmodifiedAccelerator(e); KeySequence sequence= KeySequence.getInstance(SWTKeySupport.convertAcceleratorToKeyStroke(accelerator)); - if (sequence.equals(fCommandSequence)) - if (fContentAssistant.isPrefixCompletionEnabled()) + if (sequence.equals(fCommandSequence)) { + if (fContentAssistant.isPrefixCompletionEnabled()) { incrementalComplete(); - else + } else { showProposals(false); + } + } } } @@ -352,11 +361,13 @@ public void keyPressed(KeyEvent e) { private final Runnable fFilterRunnable= new Runnable() { @Override public void run() { - if (!fIsFilterPending.compareAndSet(true, false)) + if (!fIsFilterPending.compareAndSet(true, false)) { return; + } - if (!isValid(fContentAssistSubjectControlAdapter.getControl())) + if (!isValid(fContentAssistSubjectControlAdapter.getControl())) { return; + } int offset= fContentAssistSubjectControlAdapter.getSelectedRange().x; List proposals= null; @@ -371,9 +382,9 @@ public void run() { } fFilterOffset= offset; - if (proposals != null && !proposals.isEmpty()) + if (proposals != null && !proposals.isEmpty()) { setProposals(proposals, fIsFilteredSubset); - else { + } else { hide(); if (fContentAssistant.isAutoActivation() && offset > 0 && event != null) { try { @@ -489,8 +500,9 @@ public CompletionProposalPopup(ContentAssistant contentAssistant, IContentAssist */ public String showProposals(final boolean autoActivated) { - if (fKeyListener == null) + if (fKeyListener == null) { fKeyListener= new ProposalSelectionListener(); + } final Control control= fContentAssistSubjectControlAdapter.getControl(); @@ -507,8 +519,9 @@ public String showProposals(final boolean autoActivated) { fComputedProposals= computeProposals(fInvocationOffset); int count= (fComputedProposals == null ? 0 : fComputedProposals.size()); - if (count == 0 && hideWhenNoProposals(autoActivated)) + if (count == 0 && hideWhenNoProposals(autoActivated)) { return; + } if (count == 1 && !autoActivated && canAutoInsert(fComputedProposals.get(0))) { insertProposal(fComputedProposals.get(0), (char) 0, 0, fInvocationOffset); @@ -539,8 +552,9 @@ boolean hideWhenNoProposals(boolean autoActivated) { if (autoActivated || !fContentAssistant.isShowEmptyList()) { if (!autoActivated) { Control control= fContentAssistSubjectControlAdapter.getControl(); - if (control != null && !control.isDisposed()) + if (control != null && !control.isDisposed()) { control.getDisplay().beep(); + } } hide(); return true; @@ -600,8 +614,9 @@ String getErrorMessage() { * Creates the proposal selector. */ void createProposalSelector() { - if (isValid(fProposalShell)) + if (isValid(fProposalShell)) { return; + } Control control= fContentAssistSubjectControlAdapter.getControl(); fProposalShell= new Shell(control.getShell(), SWT.ON_TOP | SWT.RESIZE ); @@ -612,12 +627,14 @@ void createProposalSelector() { fProposalTable.addListener(SWT.SetData, listener); 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, true); + } GridLayout layout= new GridLayout(); layout.marginWidth= 0; @@ -721,8 +738,9 @@ int getMinimalHeight() { Rectangle trim= fProposalTable.computeTrim(0, 0, SWT.DEFAULT, items); height= trim.height; } - if (isValid(fMessageText)) + if (isValid(fMessageText)) { height+= fMessageText.getSize().y + 1; + } return height; } @@ -795,8 +813,9 @@ public void focusLost(FocusEvent e) { */ private Color getBackgroundColor(Control control) { Color c= fContentAssistant.getProposalSelectorBackground(); - if (c == null) + if (c == null) { c= JFaceResources.getColorRegistry().get(JFacePreferences.CONTENT_ASSIST_BACKGROUND_COLOR); + } return c; } @@ -809,8 +828,9 @@ private Color getBackgroundColor(Control control) { */ private Color getForegroundColor(Control control) { Color c= fContentAssistant.getProposalSelectorForeground(); - if (c == null) + if (c == null) { c= JFaceResources.getColorRegistry().get(JFacePreferences.CONTENT_ASSIST_FOREGROUND_COLOR); + } return c; } @@ -829,8 +849,9 @@ private void createMessageText() { Font font= fMessageText.getFont(); Display display= fProposalShell.getDisplay(); FontData[] fontDatas= font.getFontData(); - for (FontData fontData : fontDatas) + for (FontData fontData : fontDatas) { fontData.setHeight(fontData.getHeight() * 9 / 10); + } fMessageTextFont= new Font(display, fontDatas); } fMessageText.setFont(fMessageTextFont); @@ -903,8 +924,9 @@ private void handleSetData(Event event) { } item.setText(displayString); - if (fIsColoredLabelsSupportEnabled) + if (fIsColoredLabelsSupportEnabled) { TableOwnerDrawSupport.storeStyleRanges(item, 0, styleRanges); + } item.setImage(image); item.setData(current); @@ -923,12 +945,14 @@ private ICompletionProposal getSelectedProposal() { /* Make sure that there is no filter runnable pending. * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=31427 */ - if (fIsFilterPending.get()) + if (fIsFilterPending.get()) { fFilterRunnable.run(); + } // filter runnable may have hidden the proposals - if (!isValid(fProposalTable)) + if (!isValid(fProposalTable)) { return null; + } int i= fProposalTable.getSelectionIndex(); List proposals= fFilteredProposals; @@ -947,8 +971,9 @@ private ICompletionProposal getSelectedProposal() { private void insertSelectedProposalWithMask(int stateMask) { ICompletionProposal p= getSelectedProposal(); hide(); - if (p != null) + if (p != null) { insertProposal(p, (char) 0, stateMask, fContentAssistSubjectControlAdapter.getSelectedRange().x); + } } /** @@ -984,8 +1009,9 @@ public boolean ownsFocusShell() { target= extension.getRewriteTarget(); } - if (target != null) + if (target != null) { target.beginCompoundChange(); + } if (fViewer instanceof IEditingSupportRegistry registry) { registry.register(helper); @@ -1014,19 +1040,22 @@ public boolean ownsFocusShell() { if (p instanceof ICompletionProposalExtension e) { contextInformationOffset= e.getContextInformationPosition(); } else { - if (selection == null) + if (selection == null) { selection= fContentAssistSubjectControlAdapter.getSelectedRange(); + } contextInformationOffset= selection.x + selection.y; } fContentAssistant.showContextInformation(info, contextInformationOffset); - } else + } else { fContentAssistant.showContextInformation(null, -1); + } } finally { - if (target != null) + if (target != null) { target.endCompoundChange(); + } if (fViewer instanceof IEditingSupportRegistry registry) { registry.unregister(helper); @@ -1042,8 +1071,9 @@ public boolean ownsFocusShell() { */ public boolean hasFocus() { if (isValid(fProposalShell)) { - if ((fProposalShell.getDisplay().getActiveShell() == fProposalShell)) + if ((fProposalShell.getDisplay().getActiveShell() == fProposalShell)) { return true; + } /* * We have to delegate this query to the additional info controller * as well, since the content assistant is the widget token owner @@ -1052,13 +1082,15 @@ public boolean hasFocus() { */ if (fAdditionalInfoController != null) { IInformationControl informationControl= fAdditionalInfoController.getCurrentInformationControl2(); - if (informationControl != null && informationControl.isFocusControl()) + if (informationControl != null && informationControl.isFocusControl()) { return true; + } InformationControlReplacer replacer= fAdditionalInfoController.getInternalAccessor().getInformationControlReplacer(); if (replacer != null) { informationControl= replacer.getCurrentInformationControl2(); - if (informationControl != null && informationControl.isFocusControl()) + if (informationControl != null && informationControl.isFocusControl()) { return true; + } } } } @@ -1111,8 +1143,9 @@ public void hide() { private void unregister() { if (fDocumentListener != null) { IDocument document= fContentAssistSubjectControlAdapter.getDocument(); - if (document != null) + if (document != null) { document.removeDocumentListener(fDocumentListener); + } fDocumentListener= null; } fDocumentEvents.clear(); @@ -1156,12 +1189,14 @@ public boolean isActive() { void setProposals(List proposals, boolean isFilteredSubset) { List oldProposals= fFilteredProposals; ICompletionProposal oldProposal= getSelectedProposal(); // may trigger filtering and a reentrant call to setProposals() - if (oldProposals != fFilteredProposals) // reentrant call was first - abort + if (oldProposals != fFilteredProposals) { // reentrant call was first - abort return; + } if (isValid(fProposalTable)) { - if (oldProposal instanceof ICompletionProposalExtension2 && fViewer != null) + if (oldProposal instanceof ICompletionProposalExtension2 && fViewer != null) { ((ICompletionProposalExtension2) oldProposal).unselected(fViewer); + } if (proposals == null || proposals.isEmpty()) { fEmptyProposal.fOffset= fFilterOffset; @@ -1182,8 +1217,9 @@ void setProposals(List proposals, boolean isFilteredSubset) 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); + } selectProposal(0, false); } @@ -1227,8 +1263,9 @@ void displayProposals() { */ void displayProposals(boolean showPopup) { - if (!isValid(fProposalShell) || !isValid(fProposalTable)) + if (!isValid(fProposalShell) || !isValid(fProposalTable)) { return; + } if (fContentAssistant.addContentAssistListener(this, ContentAssistant.PROPOSAL_SELECTOR)) { @@ -1237,8 +1274,9 @@ void displayProposals(boolean showPopup) { if (showPopup) { configureAndMakeVisible(); } - } else + } else { hide(); + } } private void configureAndMakeVisible() { @@ -1272,8 +1310,9 @@ public boolean ownsFocusShell() { */ fProposalShell.setVisible(true); // may run event loop on GTK // transfer focus since no verify key listener can be attached - if (!fContentAssistSubjectControlAdapter.supportsVerifyKeyListener() && isValid(fProposalShell)) + if (!fContentAssistSubjectControlAdapter.supportsVerifyKeyListener() && isValid(fProposalShell)) { fProposalShell.setFocus(); // may run event loop on GTK ?? + } if (fAdditionalInfoController != null && isValid(fProposalTable)) { fAdditionalInfoController.install(fProposalTable); @@ -1291,19 +1330,22 @@ void ensureDocumentListenerInstalled() { 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= fContentAssistSubjectControlAdapter.getDocument(); - if (document != null) + if (document != null) { document.addDocumentListener(fDocumentListener); + } } } @@ -1313,8 +1355,9 @@ public boolean verifyKey(VerifyEvent e) { return false; } - if (!isValid(fProposalShell)) + if (!isValid(fProposalShell)) { return true; + } char key= e.character; if (key == 0) { @@ -1330,26 +1373,30 @@ public boolean verifyKey(VerifyEvent e) { case SWT.ARROW_UP : newSelection -= 1; - if (newSelection < 0) + if (newSelection < 0) { newSelection= itemCount - 1; + } break; case SWT.ARROW_DOWN : newSelection += 1; - if (newSelection > itemCount - 1) + if (newSelection > itemCount - 1) { newSelection= 0; + } break; case SWT.PAGE_DOWN : newSelection += visibleRows; - if (newSelection >= itemCount) + if (newSelection >= itemCount) { newSelection= itemCount - 1; + } break; case SWT.PAGE_UP : newSelection -= visibleRows; - if (newSelection < 0) + if (newSelection < 0) { newSelection= 0; + } break; case SWT.HOME : @@ -1361,8 +1408,9 @@ public boolean verifyKey(VerifyEvent e) { break; default : - if (e.keyCode != SWT.CAPS_LOCK && e.keyCode != SWT.MOD1 && e.keyCode != SWT.MOD2 && e.keyCode != SWT.MOD3 && e.keyCode != SWT.MOD4) + if (e.keyCode != SWT.CAPS_LOCK && e.keyCode != SWT.MOD1 && e.keyCode != SWT.MOD2 && e.keyCode != SWT.MOD3 && e.keyCode != SWT.MOD4) { hide(); + } return true; } @@ -1393,8 +1441,9 @@ public boolean verifyKey(VerifyEvent e) { case SWT.BS: { try { - if (fFilterOffset > 0 && fContentAssistSubjectControlAdapter.getDocument().getChar(fFilterOffset - 1) == SWT.SPACE) + if (fFilterOffset > 0 && fContentAssistSubjectControlAdapter.getDocument().getChar(fFilterOffset - 1) == SWT.SPACE) { hide(); + } } catch (BadLocationException e1) { // ignore error } @@ -1429,8 +1478,9 @@ public boolean verifyKey(VerifyEvent e) { private void selectProposal(int index, boolean smartToggle) { ICompletionProposal oldProposal= getSelectedProposal(); - if (oldProposal instanceof ICompletionProposalExtension2 && fViewer != null) + if (oldProposal instanceof ICompletionProposalExtension2 && fViewer != null) { ((ICompletionProposalExtension2) oldProposal).unselected(fViewer); + } List proposals= fFilteredProposals; if (proposals == null || index >= proposals.size()) { @@ -1439,8 +1489,9 @@ private void selectProposal(int index, boolean smartToggle) { } ICompletionProposal proposal= proposals.get(index); - if (proposal instanceof ICompletionProposalExtension2 && fViewer != null) + if (proposal instanceof ICompletionProposalExtension2 && fViewer != null) { ((ICompletionProposalExtension2) proposal).selected(fViewer, smartToggle); + } fireSelectionEvent(proposal, smartToggle); @@ -1448,8 +1499,9 @@ private void selectProposal(int index, boolean smartToggle) { fProposalTable.setSelection(index); fProposalTable.showSelection(); - if (fAdditionalInfoController != null) + if (fAdditionalInfoController != null) { fAdditionalInfoController.handleTableSelectionChanged(); + } } /** @@ -1483,12 +1535,14 @@ private void fireAppliedEvent(ICompletionProposal proposal) { */ 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; @@ -1556,16 +1610,18 @@ List computeFilteredProposals(int offset, DocumentEvent eve if (proposal instanceof ICompletionProposalExtension2 p) { try { - if (p.validate(document, offset, event)) + if (p.validate(document, offset, event)) { filtered.add(proposal); + } } catch (RuntimeException e) { // Make sure that poorly behaved completion proposers do not break filtering. } } else if (proposal instanceof ICompletionProposalExtension p) { try { - if (p.isValidFor(document, offset)) + if (p.isValidFor(document, offset)) { filtered.add(proposal); + } } catch (RuntimeException e) { // Make sure that poorly behaved completion proposers do not break filtering. } @@ -1630,11 +1686,13 @@ public String incrementalComplete() { } else { final Control control= fContentAssistSubjectControlAdapter.getControl(); - if (fKeyListener == null) + if (fKeyListener == null) { fKeyListener= new ProposalSelectionListener(); + } - if (!isValid(fProposalShell) && !control.isDisposed()) + if (!isValid(fProposalShell) && !control.isDisposed()) { fContentAssistSubjectControlAdapter.addKeyListener(fKeyListener); + } BusyIndicator.showWhile(control.getDisplay(), () -> { @@ -1645,17 +1703,18 @@ public String incrementalComplete() { List proposals= fFilteredProposals; int count= (proposals == null ? 0 : proposals.size()); - if (count == 0 && hideWhenNoProposals(false)) + if (count == 0 && hideWhenNoProposals(false)) { return; + } if (proposals != null && proposals.size() == 1 && canAutoInsert(proposals.get(0))) { insertProposal(proposals.get(0), (char) 0, 0, fInvocationOffset); hide(); } else { ensureDocumentListenerInstalled(); - if (count > 0 && completeCommonPrefix()) + if (count > 0 && completeCommonPrefix()) { hide(); - else { + } else { fComputedProposals= proposals; createProposalSelector(); setProposals(fComputedProposals, false); @@ -1710,13 +1769,15 @@ boolean completeCommonPrefix() { for (int i= 0; i < fFilteredProposals.size(); i++) { ICompletionProposal proposal= fFilteredProposals.get(i); - if (!(proposal instanceof ICompletionProposalExtension3)) + if (!(proposal instanceof ICompletionProposalExtension3)) { return false; + } int start= ((ICompletionProposalExtension3)proposal).getPrefixCompletionStart(document, fFilterOffset); CharSequence insertion= ((ICompletionProposalExtension3)proposal).getPrefixCompletionText(document, fFilterOffset); - if (insertion == null) + if (insertion == null) { insertion= TextProcessor.deprocess(proposal.getDisplayString()); + } try { int prefixLength= fFilterOffset - start; int relativeCompletionOffset= Math.min(insertion.length(), prefixLength); @@ -1725,10 +1786,11 @@ boolean completeCommonPrefix() { isWrongCaseMatch= false; rightCase.add(proposal); CharSequence newPostfix= insertion.subSequence(relativeCompletionOffset, insertion.length()); - if (rightCasePostfix == null) + if (rightCasePostfix == null) { rightCasePostfix= new StringBuilder(newPostfix.toString()); - else + } else { truncatePostfix(rightCasePostfix, newPostfix, false); + } } else if (i == 0 || isWrongCaseMatch) { String insertionStrLowerCase= insertion.toString().toLowerCase(); String prefixLowerCase= prefix.toLowerCase(); @@ -1757,23 +1819,26 @@ boolean completeCommonPrefix() { } else { newPostfix= insertion.subSequence(relativeCompletionOffset, insertion.length()); } - if (wrongCasePostfix == null) + if (wrongCasePostfix == null) { wrongCasePostfix= new StringBuilder(newPostfix.toString()); - else + } else { truncatePostfix(wrongCasePostfix, newPostfix, hasMixedProposals); + } wrongCase.add(proposal); } else { return false; } - } else + } else { return false; + } } catch (BadLocationException e2) { // bail out silently return false; } - if (rightCasePostfix != null && rightCasePostfix.length() == 0 && rightCase.size() > 1) + if (rightCasePostfix != null && rightCasePostfix.length() == 0 && rightCase.size() > 1) { return false; + } } // 2: replace single proposals @@ -1799,19 +1864,22 @@ boolean completeCommonPrefix() { // 3: replace post- / prefixes CharSequence prefix; - if (isWrongCaseMatch) + if (isWrongCaseMatch) { prefix= wrongCasePrefix; - else + } else { prefix= ""; //$NON-NLS-1$ + } CharSequence postfix; - if (isWrongCaseMatch) + if (isWrongCaseMatch) { postfix= wrongCasePostfix; - else + } else { postfix= rightCasePostfix; + } - if (prefix == null || postfix == null) + if (prefix == null || postfix == null) { return false; + } try { // 4: check if parts of the postfix are already in the document @@ -1849,8 +1917,9 @@ private boolean hasMixedProposals() { boolean hasSubstringMatch= false; boolean hasPrefixMatch= false; for (ICompletionProposal proposal : fFilteredProposals) { - if (!(proposal instanceof ICompletionProposalExtension3)) + if (!(proposal instanceof ICompletionProposalExtension3)) { return false; + } int start= ((ICompletionProposalExtension3) proposal).getPrefixCompletionStart(document, fFilterOffset); CharSequence insertion= ((ICompletionProposalExtension3) proposal).getPrefixCompletionText(document, fFilterOffset); @@ -1880,8 +1949,9 @@ private boolean hasMixedProposals() { * @since 3.1 */ private boolean isPrefixCompatible(CharSequence oneSequence, int oneOffset, CharSequence twoSequence, int twoOffset, IDocument document, boolean ignoreCase) throws BadLocationException { - if (oneSequence == null || twoSequence == null) + if (oneSequence == null || twoSequence == null) { return true; + } int min= Math.min(oneOffset, twoOffset); int oneEnd= oneOffset + oneSequence.length(); @@ -1930,8 +2000,9 @@ private void truncatePostfix(StringBuilder buffer, CharSequence sequence, boolea */ void setMessage(String message) { Assert.isNotNull(message); - if (isActive() && fMessageText != null && !fMessageText.isDisposed()) + if (isActive() && fMessageText != null && !fMessageText.isDisposed()) { fMessageText.setText(message + " "); //$NON-NLS-1$ + } } /** @@ -1953,8 +2024,9 @@ void setEmptyMessage(String message) { * @since 3.2 */ public void setStatusLineVisible(boolean show) { - if (!isActive() || show == (fMessageText != null && !fMessageText.isDisposed())) + if (!isActive() || show == (fMessageText != null && !fMessageText.isDisposed())) { return; // nothing to do + } if (show) { createMessageText(); diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistSubjectControlAdapter.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistSubjectControlAdapter.java index f045753e91b..b69fddaff5c 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistSubjectControlAdapter.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistSubjectControlAdapter.java @@ -81,51 +81,58 @@ public ContentAssistSubjectControlAdapter(ITextViewer viewer) { @Override public int getLineHeight() { - if (fContentAssistSubjectControl != null) + if (fContentAssistSubjectControl != null) { return fContentAssistSubjectControl.getLineHeight(); + } return fViewer.getTextWidget().getLineHeight(getCaretOffset()); } @Override public Control getControl() { - if (fContentAssistSubjectControl != null) + if (fContentAssistSubjectControl != null) { return fContentAssistSubjectControl.getControl(); + } return fViewer.getTextWidget(); } @Override public Point getLocationAtOffset(int offset) { - if (fContentAssistSubjectControl != null) + if (fContentAssistSubjectControl != null) { return fContentAssistSubjectControl.getLocationAtOffset(offset); + } return fViewer.getTextWidget().getLocationAtOffset(offset); } @Override public Point getWidgetSelectionRange() { - if (fContentAssistSubjectControl != null) + if (fContentAssistSubjectControl != null) { return fContentAssistSubjectControl.getWidgetSelectionRange(); + } return fViewer.getTextWidget().getSelectionRange(); } @Override public Point getSelectedRange() { - if (fContentAssistSubjectControl != null) + if (fContentAssistSubjectControl != null) { return fContentAssistSubjectControl.getSelectedRange(); + } return fViewer.getSelectedRange(); } @Override public int getCaretOffset() { - if (fContentAssistSubjectControl != null) + if (fContentAssistSubjectControl != null) { return fContentAssistSubjectControl.getCaretOffset(); + } return fViewer.getTextWidget().getCaretOffset(); } @Override public String getLineDelimiter() { - if (fContentAssistSubjectControl != null) + if (fContentAssistSubjectControl != null) { return fContentAssistSubjectControl.getLineDelimiter(); + } return fViewer.getTextWidget().getLineDelimiter(); } @@ -139,24 +146,27 @@ public boolean isValidWidgetOffset(int widgetOffset) { @Override public void addKeyListener(KeyListener keyListener) { - if (fContentAssistSubjectControl != null) + if (fContentAssistSubjectControl != null) { fContentAssistSubjectControl.addKeyListener(keyListener); - else + } else { fViewer.getTextWidget().addKeyListener(keyListener); + } } @Override public void removeKeyListener(KeyListener keyListener) { - if (fContentAssistSubjectControl != null) + if (fContentAssistSubjectControl != null) { fContentAssistSubjectControl.removeKeyListener(keyListener); - else + } else { fViewer.getTextWidget().removeKeyListener(keyListener); + } } @Override public IDocument getDocument() { - if (fContentAssistSubjectControl != null) + if (fContentAssistSubjectControl != null) { return fContentAssistSubjectControl.getDocument(); + } return fViewer.getDocument(); } @@ -180,9 +190,9 @@ public boolean prependVerifyKeyListener(VerifyKeyListener verifyKeyListener) { @Override public boolean appendVerifyKeyListener(VerifyKeyListener verifyKeyListener) { - if (fContentAssistSubjectControl != null) + if (fContentAssistSubjectControl != null) { return fContentAssistSubjectControl.appendVerifyKeyListener(verifyKeyListener); - else if (fViewer instanceof ITextViewerExtension extension) { + } else if (fViewer instanceof ITextViewerExtension extension) { extension.appendVerifyKeyListener(verifyKeyListener); return true; } else { @@ -203,33 +213,37 @@ public void removeVerifyKeyListener(VerifyKeyListener verifyKeyListener) { extension.removeVerifyKeyListener(verifyKeyListener); } else { StyledText textWidget= fViewer.getTextWidget(); - if (isValid(textWidget)) + if (isValid(textWidget)) { textWidget.removeVerifyKeyListener(verifyKeyListener); + } } } @Override public void setEventConsumer(IEventConsumer eventConsumer) { - if (fContentAssistSubjectControl != null) + if (fContentAssistSubjectControl != null) { fContentAssistSubjectControl.setEventConsumer(eventConsumer); - else + } else { fViewer.setEventConsumer(eventConsumer); + } } @Override public void setSelectedRange(int i, int j) { - if (fContentAssistSubjectControl != null) + if (fContentAssistSubjectControl != null) { fContentAssistSubjectControl.setSelectedRange(i, j); - else + } else { fViewer.setSelectedRange(i, j); + } } @Override public void revealRange(int i, int j) { - if (fContentAssistSubjectControl != null) + if (fContentAssistSubjectControl != null) { fContentAssistSubjectControl.revealRange(i, j); - else + } else { fViewer.revealRange(i, j); + } } /* @@ -237,8 +251,9 @@ public void revealRange(int i, int j) { */ @Override public boolean supportsVerifyKeyListener() { - if (fContentAssistSubjectControl != null) + if (fContentAssistSubjectControl != null) { return fContentAssistSubjectControl.supportsVerifyKeyListener(); + } return true; } @@ -251,8 +266,9 @@ public boolean supportsVerifyKeyListener() { * @see IContentAssistProcessor#getCompletionProposalAutoActivationCharacters() */ Set getContentAssistProcessors(ContentAssistant contentAssistant, int offset) { - if (fContentAssistSubjectControl != null) + if (fContentAssistSubjectControl != null) { return contentAssistant.getProcessors(fContentAssistSubjectControl, offset); + } return contentAssistant.getProcessors(fViewer, offset); } @@ -268,12 +284,14 @@ Set getContentAssistProcessors(ContentAssistant content */ CompletionProposalPopup createCompletionProposalPopup(ContentAssistant contentAssistant, AdditionalInfoController controller, boolean asynchronous) { if (asynchronous) { - if (fContentAssistSubjectControl != null) + if (fContentAssistSubjectControl != null) { return new AsyncCompletionProposalPopup(contentAssistant, fContentAssistSubjectControl, controller); + } return new AsyncCompletionProposalPopup(contentAssistant, fViewer, controller); } else { - if (fContentAssistSubjectControl != null) + if (fContentAssistSubjectControl != null) { return new CompletionProposalPopup(contentAssistant, fContentAssistSubjectControl, controller); + } return new CompletionProposalPopup(contentAssistant, fViewer, controller); } } @@ -285,8 +303,9 @@ CompletionProposalPopup createCompletionProposalPopup(ContentAssistant contentAs * @return the context info popup or null */ ContextInformationPopup createContextInfoPopup(ContentAssistant contentAssistant) { - if (fContentAssistSubjectControl != null) + if (fContentAssistSubjectControl != null) { return new ContextInformationPopup(contentAssistant, fContentAssistSubjectControl); + } return new ContextInformationPopup(contentAssistant, fViewer); } @@ -302,8 +321,9 @@ ContextInformationPopup createContextInfoPopup(ContentAssistant contentAssistant * @return an validator */ public IContextInformationValidator getContextInformationValidator(ContentAssistant contentAssistant, int offset) { - if (fContentAssistSubjectControl != null) + if (fContentAssistSubjectControl != null) { return contentAssistant.getContextInformationValidator(fContentAssistSubjectControl, offset); + } return contentAssistant.getContextInformationValidator(fViewer, offset); } @@ -317,8 +337,9 @@ public IContextInformationValidator getContextInformationValidator(ContentAssist * @return a presenter */ public IContextInformationPresenter getContextInformationPresenter(ContentAssistant contentAssistant, int offset) { - if (fContentAssistSubjectControl != null) + if (fContentAssistSubjectControl != null) { return contentAssistant.getContextInformationPresenter(fContentAssistSubjectControl, offset); + } return contentAssistant.getContextInformationPresenter(fViewer, offset); } @@ -329,10 +350,12 @@ public IContextInformationPresenter getContextInformationPresenter(ContentAssist */ public void installValidator(ContextFrame frame) { if (fContentAssistSubjectControl != null) { - if (frame.fValidator instanceof ISubjectControlContextInformationValidator) + if (frame.fValidator instanceof ISubjectControlContextInformationValidator) { ((ISubjectControlContextInformationValidator) frame.fValidator).install(frame.fInformation, fContentAssistSubjectControl, frame.fOffset); - } else + } + } else { frame.fValidator.install(frame.fInformation, fViewer, frame.fOffset); + } } /** @@ -342,10 +365,12 @@ public void installValidator(ContextFrame frame) { */ public void installContextInformationPresenter(ContextFrame frame) { if (fContentAssistSubjectControl != null) { - if (frame.fPresenter instanceof ISubjectControlContextInformationPresenter) + if (frame.fPresenter instanceof ISubjectControlContextInformationPresenter) { ((ISubjectControlContextInformationPresenter) frame.fValidator).install(frame.fInformation, fContentAssistSubjectControl, frame.fBeginOffset); - } else + } + } else { frame.fPresenter.install(frame.fInformation, fViewer, frame.fBeginOffset); + } } /** @@ -359,25 +384,28 @@ public void installContextInformationPresenter(ContextFrame frame) { * @see IContentAssistProcessor#computeContextInformation(ITextViewer, int) */ public IContextInformation[] computeContextInformation(ContentAssistant contentAssistant, int offset) { - if (fContentAssistSubjectControl != null) + if (fContentAssistSubjectControl != null) { return contentAssistant.computeContextInformation(fContentAssistSubjectControl, offset); + } return contentAssistant.computeContextInformation(fViewer, offset); } @Override public boolean addSelectionListener(SelectionListener selectionListener) { - if (fContentAssistSubjectControl != null) + if (fContentAssistSubjectControl != null) { return fContentAssistSubjectControl.addSelectionListener(selectionListener); + } fViewer.getTextWidget().addSelectionListener(selectionListener); return true; } @Override public void removeSelectionListener(SelectionListener selectionListener) { - if (fContentAssistSubjectControl != null) + if (fContentAssistSubjectControl != null) { fContentAssistSubjectControl.removeSelectionListener(selectionListener); - else + } else { fViewer.getTextWidget().removeSelectionListener(selectionListener); + } } } diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistant.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistant.java index 3428fe00857..8e895b61437 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistant.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistant.java @@ -183,8 +183,9 @@ private void updateCurrentCaretInfo() { protected void uninstall() { Control shell= fShell; fShell= null; - if (isValid(shell)) + if (isValid(shell)) { shell.removeControlListener(this); + } Control control= fControl; fControl= null; @@ -241,16 +242,14 @@ public void focusLost(FocusEvent e) { Display d= control.getDisplay(); if (d != null) { d.asyncExec(() -> { - if (!fProposalPopup.hasFocus() && (fContextInfoPopup == null || !fContextInfoPopup.hasFocus())) + if (!fProposalPopup.hasFocus() && (fContextInfoPopup == null || !fContextInfoPopup.hasFocus())) { hide(); + } }); } } } - /* - * @seeDisposeListener#widgetDisposed(DisposeEvent) - */ @Override public void widgetDisposed(DisposeEvent e) { /* @@ -305,8 +304,9 @@ public void run() { try { while (true) { synchronized (fMutex) { - if (fAutoActivationDelay != 0) + if (fAutoActivationDelay != 0) { fMutex.wait(fAutoActivationDelay); + } if (fIsReset) { fIsReset= false; continue; @@ -330,18 +330,21 @@ protected void reset(int showStyle) { protected void stop() { Thread threadToStop= fThread; - if (threadToStop != null && threadToStop.isAlive()) + if (threadToStop != null && threadToStop.isAlive()) { threadToStop.interrupt(); + } } @Override public void keyPressed(KeyEvent 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 || e.stateMask == SWT.CONTROL || e.stateMask == SWT.COMMAND)) + if (e.character != 0 && (e.stateMask == SWT.ALT || e.stateMask == SWT.CONTROL || e.stateMask == SWT.COMMAND)) { return; + } TriggerType triggerType= getAutoActivationTriggerType(e.character); @@ -353,21 +356,22 @@ public void keyPressed(KeyEvent e) { } int showStyle; - if (triggerType == TriggerType.COMPLETION_PROPOSAL && !isProposalPopupActive()) + if (triggerType == TriggerType.COMPLETION_PROPOSAL && !isProposalPopupActive()) { showStyle= SHOW_PROPOSALS; - else { - if (triggerType == TriggerType.CONTEXT_INFORMATION && !isContextInfoPopupActive()) + } else { + if (triggerType == TriggerType.CONTEXT_INFORMATION && !isContextInfoPopupActive()) { showStyle= SHOW_CONTEXT_INFO; - else { + } else { stop(); return; } } - if (fThread != null && fThread.isAlive()) + if (fThread != null && fThread.isAlive()) { reset(showStyle); - else + } else { start(showStyle); + } } @Override @@ -376,27 +380,33 @@ public void verifyKey(VerifyEvent event) { } protected void showAssist(final int showStyle) { - if (fContentAssistSubjectControlAdapter == null) + if (fContentAssistSubjectControlAdapter == null) { return; + } final Control control= fContentAssistSubjectControlAdapter.getControl(); - if (control == null) + if (control == null) { return; + } final Display d= control.getDisplay(); - if (d == null) + if (d == null) { return; + } try { d.syncExec(() -> { - if (isProposalPopupActive()) + if (isProposalPopupActive()) { return; + } - if (control.isDisposed() || !control.isFocusControl()) + if (control.isDisposed() || !control.isFocusControl()) { return; + } if (showStyle == SHOW_PROPOSALS) { - if (!prepareToShowCompletions(true)) + if (!prepareToShowCompletions(true)) { return; + } fProposalPopup.showProposals(true); fLastAutoActivation= System.currentTimeMillis(); } else if (showStyle == SHOW_CONTEXT_INFO && fContextInfoPopup != null) { @@ -433,15 +443,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); @@ -472,8 +484,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((IContentAssistListener) fPopups[LAYOUT_PROPOSAL_SELECTOR], PROPOSAL_SELECTOR); } @@ -482,8 +495,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; @@ -492,8 +506,9 @@ public void handleEvent(Event event) { protected int getShellType(Widget shell) { for (int i= 0; i < fShells.length; i++) { - if (fShells[i] == shell) + if (fShells[i] == shell) { return i; + } } return -1; } @@ -620,28 +635,35 @@ protected void layoutContextInfoPopup(int offset) { * @since 3.3 */ protected void constrainLocation(Point point, Point shellSize, Rectangle bounds) { - if (point.x + shellSize.x > bounds.x + bounds.width) + if (point.x + shellSize.x > bounds.x + bounds.width) { point.x= bounds.x + bounds.width - shellSize.x; + } - if (point.x < bounds.x) + if (point.x < bounds.x) { point.x= bounds.x; + } - if (point.y + shellSize.y > bounds.y + bounds.height) + if (point.y + shellSize.y > bounds.y + bounds.height) { point.y= bounds.y + bounds.height - shellSize.y; + } - if (point.y < bounds.y) + if (point.y < bounds.y) { point.y= bounds.y; + } } protected Rectangle constrainHorizontally(Rectangle rect, Rectangle bounds) { // clip width - if (rect.width > bounds.width) + if (rect.width > bounds.width) { rect.width= bounds.width; + } - if (rect.x + rect.width > bounds.x + bounds.width) + if (rect.x + rect.width > bounds.x + bounds.width) { rect.x= bounds.x + bounds.width - rect.width; - if (rect.x < bounds.x) + } + if (rect.x < bounds.x) { rect.x= bounds.x; + } return rect; } @@ -669,15 +691,16 @@ protected Rectangle computeBoundsAboveBelow(Shell shell, Point preferred, int of int caretLowerY= caret.y + caret.height; int spaceBelow= bounds.y + bounds.height - caretLowerY; Rectangle rect; - if (spaceAbove >= preferred.y) + if (spaceAbove >= preferred.y) { rect= new Rectangle(caret.x, caret.y - preferred.y, preferred.x, preferred.y); - else if (spaceBelow >= preferred.y) + } else if (spaceBelow >= preferred.y) { rect= new Rectangle(caret.x, caretLowerY, preferred.x, preferred.y); - // we can't fit in the preferred size - squeeze into larger area - else if (spaceBelow <= spaceAbove) + } else if (spaceBelow <= spaceAbove) { + // we can't fit in the preferred size - squeeze into larger area rect= new Rectangle(caret.x, bounds.y, preferred.x, spaceAbove); - else + } else { rect= new Rectangle(caret.x, caretLowerY, preferred.x, spaceBelow); + } return constrainHorizontally(rect, bounds); } @@ -707,12 +730,12 @@ protected Rectangle computeBoundsBelowAbove(Shell shell, Point preferred, int of int spaceBelow= bounds.y + bounds.height - (caret.y + caret.height); Rectangle rect; boolean switched= false; - if (spaceBelow >= preferred.y) + if (spaceBelow >= preferred.y) { rect= new Rectangle(caret.x, caret.y + caret.height, preferred.x, preferred.y); - // squeeze in below if we have at least threshold space - else if (spaceBelow >= threshold) + } else if (spaceBelow >= threshold) { + // squeeze in below if we have at least threshold space rect= new Rectangle(caret.x, caret.y + caret.height, preferred.x, spaceBelow); - else if (spaceAbove >= preferred.y) { + } else if (spaceAbove >= preferred.y) { rect= new Rectangle(caret.x, caret.y - preferred.y, preferred.x, preferred.y); switched= true; } else if (spaceBelow >= spaceAbove) { @@ -723,8 +746,9 @@ else if (spaceAbove >= preferred.y) { switched= true; } - if (popup != null) + if (popup != null) { popup.switchedPositionToAbove(switched); + } return constrainHorizontally(rect, bounds); } @@ -759,14 +783,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((IContentAssistListener) 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((IContentAssistListener) fPopups[LAYOUT_PROPOSAL_SELECTOR], PROPOSAL_SELECTOR); + } break; case LAYOUT_CONTEXT_INFO_POPUP: break; @@ -831,13 +857,11 @@ public void verifyKey(VerifyEvent e) { } } } - if (fAutoAssistListener != null) + if (fAutoAssistListener != null) { fAutoAssistListener.keyPressed(e); + } } - /* - * @see IEventConsumer#processEvent - */ @Override public void processEvent(VerifyEvent event) { @@ -847,8 +871,9 @@ public void processEvent(VerifyEvent event) { for (IContentAssistListener listener : listeners) { if (listener != null) { listener.processEvent(event); - if (!event.doit) + if (!event.doit) { return; + } } } } @@ -1144,13 +1169,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, Collections.singleton(processor)); + } } /** @@ -1165,8 +1192,9 @@ public void setContentAssistProcessor(IContentAssistProcessor processor, String public void addContentAssistProcessor(IContentAssistProcessor processor, String contentType) { Assert.isNotNull(contentType); - if (fProcessors == null) + if (fProcessors == null) { fProcessors= new HashMap<>(); + } if (processor == null) { fProcessors.remove(contentType); @@ -1190,13 +1218,11 @@ public void removeContentAssistProcessor(IContentAssistProcessor processor) { } } - /* - * @see IContentAssistant#getContentAssistProcessor - */ @Override public IContentAssistProcessor getContentAssistProcessor(String contentType) { - if (fProcessors == null) + if (fProcessors == null) { return null; + } Set res = fProcessors.get(contentType); if (res == null || res.isEmpty()) { @@ -1216,8 +1242,9 @@ public IContentAssistProcessor getContentAssistProcessor(String contentType) { * @since 3.12 */ Set getContentAssistProcessors(String contentType) { - if (fProcessors == null) + if (fProcessors == null) { return null; + } Set res = fProcessors.get(contentType); if (res == null || res.isEmpty()) { @@ -1232,8 +1259,9 @@ Set getContentAssistProcessors(String contentType) { * @since 3.15 */ TriggerType getAutoActivationTriggerType(char c) { - if (fProcessors == null) + if (fProcessors == null) { return TriggerType.NONE; + } int offset= fContentAssistSubjectControlAdapter.getSelectedRange().x; Set processors= fContentAssistSubjectControlAdapter.getContentAssistProcessors(this, offset); if (processors == null) { @@ -1301,18 +1329,20 @@ private void manageAutoActivation(boolean start) { if ((fContentAssistSubjectControlAdapter != null) && fAutoAssistListener == null) { fAutoAssistListener= createAutoAssistListener(); // For details see https://bugs.eclipse.org/bugs/show_bug.cgi?id=49212 - if (fContentAssistSubjectControlAdapter.supportsVerifyKeyListener()) + if (fContentAssistSubjectControlAdapter.supportsVerifyKeyListener()) { fContentAssistSubjectControlAdapter.appendVerifyKeyListener(fAutoAssistListener); - else + } else { fContentAssistSubjectControlAdapter.addKeyListener(fAutoAssistListener); + } } } else if (fAutoAssistListener != null) { // For details see https://bugs.eclipse.org/bugs/show_bug.cgi?id=49212 - if (fContentAssistSubjectControlAdapter.supportsVerifyKeyListener()) + if (fContentAssistSubjectControlAdapter.supportsVerifyKeyListener()) { fContentAssistSubjectControlAdapter.removeVerifyKeyListener(fAutoAssistListener); - else + } else { fContentAssistSubjectControlAdapter.removeKeyListener(fAutoAssistListener); + } fAutoAssistListener= null; } } @@ -1553,20 +1583,12 @@ public void setInformationControlCreator(IInformationControlCreator creator) { fInformationControlCreator= creator; } - /* - * @see IControlContentAssistant#install(IContentAssistSubjectControl) - * @since 3.0 - */ protected void install(IContentAssistSubjectControl contentAssistSubjectControl) { fContentAssistSubjectControl= contentAssistSubjectControl; fContentAssistSubjectControlAdapter= new ContentAssistSubjectControlAdapter(fContentAssistSubjectControl); install(); } - /* - * @see IContentAssist#install - * @since 3.0 - */ @Override public void install(ITextViewer textViewer) { fViewer= textViewer; @@ -1580,8 +1602,9 @@ protected void install() { fInternalListener= new InternalListener(); AdditionalInfoController controller= null; - if (fInformationControlCreator != null) + if (fInformationControlCreator != null) { controller= new AdditionalInfoController(fInformationControlCreator, OpenStrategy.getPostSelectionDelay()); + } fContextInfoPopup= fContentAssistSubjectControlAdapter.createContextInfoPopup(this); fProposalPopup= fContentAssistSubjectControlAdapter.createCompletionProposalPopup(this, controller, fAsynchronous); @@ -1593,8 +1616,9 @@ protected void install() { if (isValid(fContentAssistSubjectControlAdapter.getControl())) { fContentAssistSubjectControlShell= fContentAssistSubjectControlAdapter.getControl().getShell(); fCASCSTraverseListener= e -> { - if (e.detail == SWT.TRAVERSE_ESCAPE && isProposalPopupActive()) + if (e.detail == SWT.TRAVERSE_ESCAPE && isProposalPopupActive()) { e.doit= false; + } }; fContentAssistSubjectControlShell.addTraverseListener(fCASCSTraverseListener); } @@ -1602,9 +1626,6 @@ protected void install() { manageAutoActivation(fIsAutoActivated); } - /* - * @see IContentAssist#uninstall - */ @Override public void uninstall() { hide(); @@ -1626,8 +1647,9 @@ public void uninstall() { fCloser= null; } - if (isValid(fContentAssistSubjectControlShell)) + if (isValid(fContentAssistSubjectControlShell)) { fContentAssistSubjectControlShell.removeTraverseListener(fCASCSTraverseListener); + } fCASCSTraverseListener= null; fContentAssistSubjectControlShell= null; @@ -1750,8 +1772,9 @@ boolean addContentAssistListener(IContentAssistListener listener, int type) { fCloser.install(); fContentAssistSubjectControlAdapter.setEventConsumer(fInternalListener); installKeyListener(); - } else + } else { promoteKeyListener(); + } return true; } @@ -1797,12 +1820,14 @@ private void installKeyListener() { private void releaseWidgetToken(int type) { if (fListeners[CONTEXT_SELECTOR] == null && fListeners[PROPOSAL_SELECTOR] == null) { IWidgetTokenOwner owner= null; - if (fContentAssistSubjectControl instanceof IWidgetTokenOwner) + if (fContentAssistSubjectControl instanceof IWidgetTokenOwner) { owner= (IWidgetTokenOwner) fContentAssistSubjectControl; - else if (fViewer instanceof IWidgetTokenOwner) + } else if (fViewer instanceof IWidgetTokenOwner) { owner= (IWidgetTokenOwner) fViewer; - if (owner != null) + } + if (owner != null) { owner.releaseWidgetToken(this); + } } } @@ -1837,8 +1862,9 @@ void removeContentAssistListener(IContentAssistListener listener, int type) { */ private void uninstallVerifyKeyListener() { if (fVerifyKeyListenerHooked) { - if (isValid(fContentAssistSubjectControlAdapter.getControl())) + if (isValid(fContentAssistSubjectControlAdapter.getControl())) { fContentAssistSubjectControlAdapter.removeVerifyKeyListener(fInternalListener); + } fVerifyKeyListenerHooked= false; } } @@ -1852,28 +1878,29 @@ private void uninstallVerifyKeyListener() { 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; } - /* - * @see IContentAssist#showPossibleCompletions - */ @Override public String showPossibleCompletions() { - if (!prepareToShowCompletions(false)) + if (!prepareToShowCompletions(false)) { return null; - if (fIsPrefixCompletionEnabled) + } + if (fIsPrefixCompletionEnabled) { return fProposalPopup.incrementalComplete(); + } return fProposalPopup.showProposals(false); } @Override public String completePrefix() { - if (!prepareToShowCompletions(false)) + if (!prepareToShowCompletions(false)) { return null; + } return fProposalPopup.incrementalComplete(); } @@ -1910,14 +1937,12 @@ protected void possibleCompletionsClosed() { storeCompletionProposalPopupSize(); } - /* - * @see IContentAssist#showContextInformation - */ @Override public String showContextInformation() { promoteKeyListener(); - if (fContextInfoPopup != null) + if (fContextInfoPopup != null) { return fContextInfoPopup.showContextProposals(false); + } return null; } @@ -1938,8 +1963,9 @@ protected void contextInformationClosed() { * @since 2.0 */ void showContextInformation(IContextInformation contextInformation, int offset) { - if (fContextInfoPopup != null) + if (fContextInfoPopup != null) { fContextInfoPopup.showContextInformation(contextInformation, offset); + } } /** @@ -1986,10 +2012,11 @@ Set getProcessors(IContentAssistSubjectControl contentA IDocument document= contentAssistSubjectControl.getDocument(); String type; - if (document != null) + if (document != null) { type= TextUtilities.getContentType(document, getDocumentPartitioning(), offset, true); - else + } else { type= IDocument.DEFAULT_CONTENT_TYPE; + } return getContentAssistProcessors(type); @@ -2210,8 +2237,9 @@ IContextInformationValidator getContextInformationValidator(IContentAssistSubjec */ IContextInformationPresenter getContextInformationPresenter(ITextViewer viewer, int offset) { IContextInformationValidator validator= getContextInformationValidator(viewer, offset); - if (validator instanceof IContextInformationPresenter) + if (validator instanceof IContextInformationPresenter) { return (IContextInformationPresenter) validator; + } return null; } @@ -2226,8 +2254,9 @@ IContextInformationPresenter getContextInformationPresenter(ITextViewer viewer, */ IContextInformationPresenter getContextInformationPresenter(IContentAssistSubjectControl contentAssistSubjectControl, int offset) { IContextInformationValidator validator= getContextInformationValidator(contentAssistSubjectControl, offset); - if (validator instanceof IContextInformationPresenter) + if (validator instanceof IContextInformationPresenter) { return (IContextInformationPresenter) validator; + } return null; } @@ -2260,11 +2289,13 @@ public boolean setFocus(IWidgetTokenOwner owner) { * @since 3.0 */ protected void hide() { - if (fProposalPopup != null) + if (fProposalPopup != null) { fProposalPopup.hide(); + } - if (fContextInfoPopup != null) + if (fContextInfoPopup != null) { fContextInfoPopup.hide(); + } } // ------ control's size handling dialog settings ------ @@ -2300,12 +2331,14 @@ public void setRestoreCompletionProposalSize(IDialogSettings dialogSettings) { * Stores the content assist's proposal pop-up size. */ protected void storeCompletionProposalPopupSize() { - if (fDialogSettings == null || fProposalPopup == null) + if (fDialogSettings == null || fProposalPopup == null) { return; + } Point size= fProposalPopup.getSize(); - if (size == null) + if (size == null) { return; + } fDialogSettings.put(STORE_SIZE_X, size.x); fDialogSettings.put(STORE_SIZE_Y, size.y); @@ -2317,12 +2350,14 @@ protected void storeCompletionProposalPopupSize() { * @since 3.9 */ protected void storeContextSelectorPopupSize() { - if (fDialogSettings == null || fContextInfoPopup == null) + if (fDialogSettings == null || fContextInfoPopup == null) { return; + } Point size= fContextInfoPopup.getContextSelectorPopupSize(); - if (size == null) + if (size == null) { return; + } fDialogSettings.put(STORE_CONTEXT_SELECTOR_POPUP_SIZE_X, size.x); fDialogSettings.put(STORE_CONTEXT_SELECTOR_POPUP_SIZE_Y, size.y); @@ -2335,8 +2370,9 @@ protected void storeContextSelectorPopupSize() { * @since 3.0 */ protected Point restoreCompletionProposalPopupSize() { - if (fDialogSettings == null) + if (fDialogSettings == null) { return null; + } Point size= new Point(-1, -1); @@ -2348,19 +2384,22 @@ protected Point restoreCompletionProposalPopupSize() { } // sanity check - if (size.x == -1 && size.y == -1) + if (size.x == -1 && size.y == -1) { return null; + } Rectangle maxBounds= null; - if (fContentAssistSubjectControl != null && isValid(fContentAssistSubjectControl.getControl())) + if (fContentAssistSubjectControl != null && isValid(fContentAssistSubjectControl.getControl())) { maxBounds= fContentAssistSubjectControl.getControl().getDisplay().getBounds(); - else { + } else { // fallback Display display= Display.getCurrent(); - if (display == null) + if (display == null) { display= Display.getDefault(); - if (display != null && !display.isDisposed()) + } + if (display != null && !display.isDisposed()) { maxBounds= display.getBounds(); + } } if (size.x > -1 && size.y > -1) { @@ -2384,8 +2423,9 @@ protected Point restoreCompletionProposalPopupSize() { * @since 3.9 */ protected Point restoreContextSelectorPopupSize() { - if (fDialogSettings == null) + if (fDialogSettings == null) { return null; + } Point size= new Point(-1, -1); @@ -2397,15 +2437,18 @@ protected Point restoreContextSelectorPopupSize() { } // sanity check - if (size.x == -1 && size.y == -1) + if (size.x == -1 && size.y == -1) { return null; + } Rectangle maxBounds= null; Display display= Display.getCurrent(); - if (display == null) + if (display == null) { display= Display.getDefault(); - if (display != null && !display.isDisposed()) + } + if (display != null && !display.isDisposed()) { maxBounds= display.getBounds(); + } if (size.x > -1 && size.y > -1) { if (maxBounds != null) { @@ -2495,8 +2538,9 @@ void fireSessionRestartEvent() { processors.forEach(processor -> { ContentAssistEvent event= new ContentAssistEvent(this, processor); for (ICompletionListener listener : fCompletionListeners) { - if (listener instanceof ICompletionListenerExtension) + if (listener instanceof ICompletionListenerExtension) { ((ICompletionListenerExtension)listener).assistSessionRestarted(event); + } } }); } @@ -2559,8 +2603,9 @@ boolean isShowEmptyList() { @Override public void setStatusLineVisible(boolean show) { fIsStatusLineVisible= show; - if (fProposalPopup != null) + if (fProposalPopup != null) { fProposalPopup.setStatusLineVisible(show); + } } /** @@ -2579,8 +2624,9 @@ boolean isStatusLineVisible() { public void setStatusMessage(String message) { Assert.isLegal(message != null); fMessage= message; - if (fProposalPopup != null) + if (fProposalPopup != null) { fProposalPopup.setMessage(message); + } } /** @@ -2596,8 +2642,9 @@ String getStatusMessage() { @Override public void setEmptyMessage(String message) { Assert.isLegal(message != null); - if (fProposalPopup != null) + if (fProposalPopup != null) { fProposalPopup.setEmptyMessage(message); + } } /** @@ -2621,15 +2668,12 @@ void fireSelectionEvent(ICompletionProposal proposal, boolean smartToggle) { */ void fireAppliedEvent(ICompletionProposal proposal) { for (ICompletionListener listener : fCompletionListeners) { - if (listener instanceof ICompletionListenerExtension2) + if (listener instanceof ICompletionListenerExtension2) { ((ICompletionListenerExtension2)listener).applied(proposal); + } } } - /* - * @see org.eclipse.jface.text.contentassist.IContentAssistantExtension3#setInvocationTrigger(org.eclipse.jface.bindings.keys.KeySequence) - * @since 3.2 - */ @Override public void setRepeatedInvocationTrigger(KeySequence sequence) { fRepeatedInvocationKeySequence= sequence; @@ -2672,12 +2716,14 @@ protected boolean isContextInfoPopupActive(){ */ @Override public final IHandler getHandler(String commandId) { - if (fHandlers == null) + if (fHandlers == null) { throw new IllegalStateException(); + } IHandler handler= fHandlers.get(commandId); - if (handler != null) + if (handler != null) { return handler; + } Assert.isLegal(false); return null; @@ -2691,8 +2737,9 @@ public final IHandler getHandler(String commandId) { * @since 3.4 */ protected final void registerHandler(String commandId, IHandler handler) { - if (fHandlers == null) + if (fHandlers == null) { fHandlers= new HashMap<>(2); + } fHandlers.put(commandId, handler); } diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformation.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformation.java index b5701baf105..561aa4b212c 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformation.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformation.java @@ -62,8 +62,9 @@ public ContextInformation(Image image, String contextDisplayString, String infor public boolean equals(Object object) { if (object instanceof IContextInformation contextInformation) { boolean equals= fInformationDisplayString.equalsIgnoreCase(contextInformation.getInformationDisplayString()); - if (fContextDisplayString != null) + if (fContextDisplayString != null) { equals= equals && fContextDisplayString.equalsIgnoreCase(contextInformation.getContextDisplayString()); + } return equals; } return false; @@ -87,8 +88,9 @@ public Image getImage() { @Override public String getContextDisplayString() { - if (fContextDisplayString != null) + if (fContextDisplayString != null) { return fContextDisplayString; + } return fInformationDisplayString; } } diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationPopup.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationPopup.java index 07266cbc3e7..701a6d4c306 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationPopup.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationPopup.java @@ -190,11 +190,12 @@ public String showContextProposals(final boolean autoActivated) { IContextInformation[] contexts= computeContextInformation(offset); if (contexts != null && contexts.length == 1) { ContextFrame frame1= createContextFrame(contexts[0], offset); - if (isDuplicate(frame1)) + if (isDuplicate(frame1)) { validateContextInformation(); - else + } else { // Show context information directly internalShowContextInfo(frame1); + } } else if (contexts != null && contexts.length > 0) { // if any of the proposed context matches any of the contexts on the stack, @@ -227,8 +228,9 @@ public String showContextProposals(final boolean autoActivated) { // otherwise: // Precise context must be selected - if (fLineDelimiter == null) + if (fLineDelimiter == null) { fLineDelimiter= fContentAssistSubjectControlAdapter.getLineDelimiter(); + } createContextSelector(); setContexts(contexts, index); @@ -249,14 +251,15 @@ public String showContextProposals(final boolean autoActivated) { public void showContextInformation(final IContextInformation info, final int offset) { Control control= fContentAssistSubjectControlAdapter.getControl(); BusyIndicator.showWhile(control.getDisplay(), () -> { - if (info == null) + if (info == null) { validateContextInformation(); - else { + } else { ContextFrame frame= createContextFrame(info, offset); - if (isDuplicate(frame)) + if (isDuplicate(frame)) { validateContextInformation(); - else + } else { internalShowContextInfo(frame); + } hideContextSelector(); } }); @@ -271,8 +274,9 @@ public void showContextInformation(final IContextInformation info, final int off private void internalShowContextInfo(ContextFrame frame) { if (frame != null && canShowFrame(frame)) { fContextFrameStack.push(frame); - if (fContextFrameStack.size() == 1) + if (fContextFrameStack.size() == 1) { fLastContext= null; + } internalShowContextFrame(frame, fContextFrameStack.size() == 1); validateContextInformation(); } @@ -291,7 +295,9 @@ private ContextFrame createContextFrame(IContextInformation information, int off if (validator != null) { int beginOffset= (information instanceof IContextInformationExtension i) ? i.getContextInformationPosition() : offset; - if (beginOffset == -1) beginOffset= offset; + if (beginOffset == -1) { + beginOffset= offset; + } int visibleOffset= fContentAssistSubjectControlAdapter.getWidgetSelectionRange().x - (offset - beginOffset); IContextInformationPresenter presenter = fContentAssistSubjectControlAdapter.getContextInformationPresenter(fContentAssistant, offset); return new ContextFrame(information, beginOffset, offset, visibleOffset, validator, presenter); @@ -309,10 +315,12 @@ private ContextFrame createContextFrame(IContextInformation information, int off * @since 3.0 */ private boolean isDuplicate(ContextFrame frame) { - if (frame == null) + if (frame == null) { return false; - if (fContextFrameStack.isEmpty()) + } + if (fContextFrameStack.isEmpty()) { return false; + } // stack not empty ContextFrame top= fContextFrameStack.peek(); return frame.equals(top); @@ -355,8 +363,9 @@ private void internalShowContextFrame(ContextFrame frame, boolean initial) { fContentAssistSubjectControlAdapter.installValidator(frame); if (frame.fPresenter != null) { - if (fTextPresentation == null) + if (fTextPresentation == null) { fTextPresentation= new TextPresentation(); + } fContentAssistSubjectControlAdapter.installContextInformationPresenter(frame); frame.fPresenter.updatePresentation(frame.fOffset, fTextPresentation); } @@ -364,8 +373,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(frame.fVisibleOffset); if (initial) { @@ -410,8 +420,9 @@ private String getErrorMessage() { * Creates the context information popup. This is the tool tip like overlay window. */ private void createContextInfoPopup() { - if (isValid(fContextInfoPopup)) + if (isValid(fContextInfoPopup)) { return; + } Control control= fContentAssistSubjectControlAdapter.getControl(); Display display= control.getDisplay(); @@ -422,13 +433,15 @@ private void createContextInfoPopup() { fContextInfoText= new StyledText(fContextInfoPopup, SWT.MULTI | SWT.READ_ONLY | SWT.WRAP); 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); } @@ -445,9 +458,10 @@ private void resize(int offset) { final int PAD= TEXT_PAD + BORDER_PAD; size.x += PAD; Rectangle bounds= fContentAssistant.getLayoutManager().computeBoundsAboveBelow(fContextInfoPopup, size, offset); - if (bounds.width < size.x) + if (bounds.width < size.x) { // we don't fit on the screen - try again and wrap size= fContextInfoText.computeSize(bounds.width - PAD, SWT.DEFAULT, true); + } size.x += TEXT_PAD; fContextInfoText.setSize(size); @@ -483,8 +497,9 @@ private void hideContextInfoPopup(boolean all) { } fContentAssistant.removeContentAssistListener(this, ContentAssistant.CONTEXT_INFO_POPUP); - if (fContentAssistSubjectControlAdapter.getControl() != null) + if (fContentAssistSubjectControlAdapter.getControl() != null) { fContentAssistSubjectControlAdapter.removeSelectionListener(fTextWidgetSelectionListener); + } fTextWidgetSelectionListener= null; fContextInfoPopup.setVisible(false); @@ -497,8 +512,9 @@ private void hideContextInfoPopup(boolean all) { } } - if (fContextInfoPopup == null) + if (fContextInfoPopup == null) { fContentAssistant.contextInformationClosed(); + } } /** @@ -506,8 +522,9 @@ private void hideContextInfoPopup(boolean all) { * at a given offset. */ private void createContextSelector() { - if (isValid(fContextSelectorShell)) + if (isValid(fContextSelectorShell)) { return; + } Control control= fContentAssistSubjectControlAdapter.getControl(); fContextSelectorShell= new Shell(control.getShell(), SWT.ON_TOP | SWT.RESIZE); @@ -554,19 +571,22 @@ public void controlResized(ControlEvent e) { fContextSelectorTable.setLayoutData(gd); Point size= fContentAssistant.restoreContextSelectorPopupSize(); - if (size != null) + if (size != null) { fContextSelectorShell.setSize(size); - else + } else { 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() { @@ -621,8 +641,9 @@ Point getContextSelectorPopupSize() { private void insertSelectedContext() { int i= fContextSelectorTable.getSelectionIndex(); - if (i < 0 || i >= fContextSelectorInput.length) + if (i < 0 || i >= fContextSelectorInput.length) { return; + } int offset= fContentAssistSubjectControlAdapter.getSelectedRange().x; internalShowContextInfo(createContextFrame(fContextSelectorInput[i], offset)); @@ -647,8 +668,9 @@ private void setContexts(IContextInformation[] contexts, int selectionIndex) { 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()); } @@ -661,8 +683,9 @@ private void setContexts(IContextInformation[] contexts, int selectionIndex) { * Displays the context selector. */ private void displayContextSelector() { - if (fContentAssistant.addContentAssistListener(this, ContentAssistant.CONTEXT_SELECTOR)) + if (fContentAssistant.addContentAssistListener(this, ContentAssistant.CONTEXT_SELECTOR)) { fContextSelectorShell.setVisible(true); + } } /** @@ -679,8 +702,9 @@ private void hideContextSelector() { fContextSelectorShell= null; } - if (!isValid(fContextInfoPopup)) + if (!isValid(fContextInfoPopup)) { fContentAssistant.contextInformationClosed(); + } } /** @@ -689,8 +713,9 @@ private void hideContextSelector() { * @return true if the context selector has the focus */ public boolean hasFocus() { - if (isValid(fContextSelectorShell)) + if (isValid(fContextSelectorShell)) { return fContextSelectorShell.getDisplay().getActiveShell() == fContextSelectorShell; + } return false; } @@ -715,10 +740,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; } @@ -739,26 +766,30 @@ private boolean contextSelectorKeyPressed(VerifyEvent e) { switch (e.keyCode) { case SWT.ARROW_UP : newSelection -= 1; - if (newSelection < 0) + if (newSelection < 0) { newSelection= itemCount - 1; + } break; case SWT.ARROW_DOWN : newSelection += 1; - if (newSelection > itemCount - 1) + if (newSelection > itemCount - 1) { newSelection= 0; + } break; case SWT.PAGE_DOWN : newSelection += visibleRows; - if (newSelection >= itemCount) + if (newSelection >= itemCount) { newSelection= itemCount - 1; + } break; case SWT.PAGE_UP : newSelection -= visibleRows; - if (newSelection < 0) + if (newSelection < 0) { newSelection= 0; + } break; case SWT.HOME : @@ -770,8 +801,9 @@ private boolean contextSelectorKeyPressed(VerifyEvent e) { break; default : - if (e.keyCode != SWT.CAPS_LOCK && e.keyCode != SWT.MOD1 && e.keyCode != SWT.MOD2 && e.keyCode != SWT.MOD3 && e.keyCode != SWT.MOD4) + if (e.keyCode != SWT.CAPS_LOCK && e.keyCode != SWT.MOD1 && e.keyCode != SWT.MOD2 && e.keyCode != SWT.MOD3 && e.keyCode != SWT.MOD4) { hideContextSelector(); + } return true; } @@ -812,8 +844,9 @@ private boolean contextInfoPopupKeyPressed(KeyEvent e) { validateContextInformation(); break; default: - if (e.keyCode != SWT.CAPS_LOCK && e.keyCode != SWT.MOD1 && e.keyCode != SWT.MOD2 && e.keyCode != SWT.MOD3 && e.keyCode != SWT.MOD4) + if (e.keyCode != SWT.CAPS_LOCK && e.keyCode != SWT.MOD1 && e.keyCode != SWT.MOD2 && e.keyCode != SWT.MOD3 && e.keyCode != SWT.MOD4) { hideContextInfoPopup(true); + } break; } @@ -828,10 +861,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); + } } /** @@ -855,8 +890,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(); + } } /** @@ -869,8 +905,9 @@ private void validateContextInformation() { * Otherwise, we'd validate the context information based on the * pre-key-stroke state. */ - if (!isValid(fContextInfoPopup)) + if (!isValid(fContextInfoPopup)) { return; + } fContextInfoPopup.getDisplay().asyncExec(new Runnable() { @@ -892,8 +929,9 @@ public void run() { TextPresentation.applyTextPresentation(fTextPresentation, fContextInfoText); resize(widgetOffset); break; - } else + } else { break; + } } } } diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationValidator.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationValidator.java index 971779f0816..ca763d4aaca 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationValidator.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationValidator.java @@ -52,9 +52,11 @@ public void install(IContextInformation contextInformation, ITextViewer viewer, public boolean isContextInformationValid(int offset) { IContextInformation[] infos= fProcessor.computeContextInformation(fViewer, offset); if (infos != null && infos.length > 0) { - for (IContextInformation info : infos) - if (fContextInformation.equals(info)) + for (IContextInformation info : infos) { + if (fContextInformation.equals(info)) { return true; + } + } } return false; } diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/PopupCloser.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/PopupCloser.java index 3d2cc5a139b..4f4951cda1b 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/PopupCloser.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/PopupCloser.java @@ -101,8 +101,9 @@ public void install(ContentAssistant contentAssistant, Table table, AdditionalIn fShell.addShellListener(this); fTable.addFocusListener(this); fScrollbar= fTable.getVerticalBar(); - if (fScrollbar != null) + if (fScrollbar != null) { fScrollbar.addSelectionListener(this); + } fDisplay.addFilter(SWT.Activate, this); fDisplay.addFilter(SWT.MouseVerticalWheel, this); @@ -120,13 +121,16 @@ public void install(ContentAssistant contentAssistant, Table table, AdditionalIn */ 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); + } if (fDisplay != null && ! fDisplay.isDisposed()) { fDisplay.removeFilter(SWT.Activate, this); fDisplay.removeFilter(SWT.MouseVerticalWheel, this); @@ -158,8 +162,9 @@ 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); + } }); } @@ -171,8 +176,9 @@ public void shellDeactivated(ShellEvent e) { * The asyncExec is a workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=235556 : * fContentAssistant.hasProposalPopupFocus() is still true during the shellDeactivated(..) event. */ - if (fContentAssistant != null && !fContentAssistant.hasProposalPopupFocus()) + if (fContentAssistant != null && !fContentAssistant.hasProposalPopupFocus()) { fContentAssistant.hide(); + } }); } } @@ -180,8 +186,9 @@ public void shellDeactivated(ShellEvent e) { @Override public void shellClosed(ShellEvent e) { - if (fContentAssistant != null) + if (fContentAssistant != null) { fContentAssistant.hide(); + } } @Override @@ -189,21 +196,24 @@ public void handleEvent(Event event) { switch (event.type) { case SWT.Activate: case SWT.MouseVerticalWheel: - if (fAdditionalInfoController == null) + if (fAdditionalInfoController == null) { return; - if (event.widget == fShell || event.widget == fTable || event.widget == fScrollbar) + } + if (event.widget == fShell || event.widget == fTable || event.widget == fScrollbar) { return; + } - if (fAdditionalInfoController.getInternalAccessor().getInformationControlReplacer() == null) + if (fAdditionalInfoController.getInternalAccessor().getInformationControlReplacer() == null) { fAdditionalInfoController.hideInformationControl(); - else if (!fAdditionalInfoController.getInternalAccessor().isReplaceInProgress()) { + } else if (!fAdditionalInfoController.getInternalAccessor().isReplaceInProgress()) { IInformationControl infoControl= fAdditionalInfoController.getCurrentInformationControl2(); // During isReplaceInProgress(), events can come from the replacing information control if (event.widget instanceof Control control && infoControl instanceof IInformationControlExtension5 iControl5) { - if (!(iControl5.containsControl(control))) + if (!(iControl5.containsControl(control))) { fAdditionalInfoController.hideInformationControl(); - else if (event.type == SWT.MouseVerticalWheel) + } else if (event.type == SWT.MouseVerticalWheel) { fAdditionalInfoController.getInternalAccessor().replaceInformationControl(false); + } } else if (infoControl != null && infoControl.isFocusControl()) { fAdditionalInfoController.getInternalAccessor().replaceInformationControl(true); } @@ -213,8 +223,9 @@ else if (event.type == SWT.MouseVerticalWheel) case SWT.MouseEnter: case SWT.MouseMove: case SWT.MouseUp: - if (fAdditionalInfoController == null || fAdditionalInfoController.getInternalAccessor().isReplaceInProgress()) + if (fAdditionalInfoController == null || fAdditionalInfoController.getInternalAccessor().isReplaceInProgress()) { break; + } if (event.widget instanceof Control control) { IInformationControl infoControl= fAdditionalInfoController.getCurrentInformationControl2(); if (infoControl instanceof final IInformationControlExtension5 iControl5) { @@ -234,16 +245,18 @@ else if (event.type == SWT.MouseVerticalWheel) break; case SWT.Deactivate: - if (fAdditionalInfoController == null) + if (fAdditionalInfoController == null) { break; + } InformationControlReplacer replacer= fAdditionalInfoController.getInternalAccessor().getInformationControlReplacer(); if (replacer != null && fContentAssistant != null) { IInformationControl iControl= replacer.getCurrentInformationControl2(); if (event.widget instanceof Control control && iControl instanceof IInformationControlExtension5 iControl5) { if (iControl5.containsControl(control)) { control.getDisplay().asyncExec(() -> { - if (fContentAssistant != null && !fContentAssistant.hasProposalPopupFocus()) + if (fContentAssistant != null && !fContentAssistant.hasProposalPopupFocus()) { fContentAssistant.hide(); + } }); } }