diff --git a/bundles/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionSummary.java b/bundles/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionSummary.java index b930c66cc5e..b5ac2d91c01 100644 --- a/bundles/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionSummary.java +++ b/bundles/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionSummary.java @@ -186,7 +186,7 @@ private void removeSummaries(IProgressMonitor monitor, IAnnotationModel visualAn return; } - if (bags != null && !bags.isEmpty()) { + if (bags != null && !bags.isEmpty() && extension != null) { Annotation[] deletions= new Annotation[bags.size()]; bags.toArray(deletions); if (!isCanceled(monitor)) diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningManager.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningManager.java index eed8d98fbc5..da5f509bceb 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningManager.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningManager.java @@ -158,7 +158,7 @@ private void cancel() { } private static void logCodeMiningProviderException(Throwable e) { - if (e != null && (e instanceof CancellationException || (e.getCause() != null && e.getCause() instanceof CancellationException))) { + if (e instanceof CancellationException || e.getCause() instanceof CancellationException) { return; } String PLUGIN_ID= "org.eclipse.jface.text"; //$NON-NLS-1$ 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 2d4d5db7789..6ca009a07d7 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 @@ -206,43 +206,30 @@ public void keyReleased(KeyEvent e) { } final StyledText styledText= fViewer.getTextWidget(); - if (styledText != null && !styledText.isDisposed()) + if (styledText != null && !styledText.isDisposed()) { styledText.addKeyListener(fKeyListener); + fInvocationOffset= fViewer.getSelectedRange().x; + fComputedProposals= computeProposals(fInvocationOffset); -// BusyIndicator.showWhile(styledText.getDisplay(), new Runnable() { -// public void run() { - - fInvocationOffset= fViewer.getSelectedRange().x; - // lazily compute proposals -// if (fComputedProposals == null) fComputedProposals= computeProposals(fContentAssistant.getCompletionPosition()); - fComputedProposals= computeProposals(fInvocationOffset); - - int count= (fComputedProposals == null ? 0 : fComputedProposals.length); - if (count == 0) { - - if (!autoActivated) - styledText.getDisplay().beep(); - + int count= (fComputedProposals == null ? 0 : fComputedProposals.length); + if (count == 0) { + if (!autoActivated) { + styledText.getDisplay().beep(); + } + } else { + if (count == 1 && !autoActivated && fContentAssistant.isAutoInserting()) { + insertProposal(fComputedProposals[0], (char) 0, 0, fInvocationOffset); } else { - - if (count == 1 && !autoActivated && fContentAssistant.isAutoInserting()) - - insertProposal(fComputedProposals[0], (char) 0, 0, fInvocationOffset); - - else { - - if (fLineDelimiter == null) - fLineDelimiter= styledText.getLineDelimiter(); - - createProposalSelector(); - setProposals(fComputedProposals); - resizeProposalSelector(true); - displayProposals(); + if (fLineDelimiter == null) { + fLineDelimiter= styledText.getLineDelimiter(); } + createProposalSelector(); + setProposals(fComputedProposals); + resizeProposalSelector(true); + displayProposals(); } -// } -// }); - + } + } return getErrorMessage(); } 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 3582d784ec7..68005bfa7a4 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 @@ -116,18 +116,14 @@ public String showContextProposals(final boolean autoActivated) { int position= fViewer.getSelectedRange().x; IContextInformation[] contexts= computeContextInformation(position); - int count= (contexts == null ? 0 : contexts.length); - if (count == 1) { - + if (contexts != null && contexts.length == 1) { // Show context information directly internalShowContextInfo(contexts[0], position); - - } else if (count > 0) { + } else if (contexts != null && contexts.length > 0) { // Precise context must be selected - - if (fLineDelimiter == null) + if (fLineDelimiter == null) { fLineDelimiter= styledText.getLineDelimiter(); - + } createContextSelector(); setContexts(contexts); displayContextSelector(); diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/DocumentCommand.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/DocumentCommand.java index cc6958e834a..a941d33b64f 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/DocumentCommand.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/DocumentCommand.java @@ -399,9 +399,9 @@ void execute(IDocument document) throws BadLocationException { Position caretPosition= null; try { if (updateCaret()) { + caretPosition= new Position(caretOffset); document.addPositionCategory(getCategory()); document.addPositionUpdater(updater); - caretPosition= new Position(caretOffset); document.addPosition(getCategory(), caretPosition); } @@ -414,7 +414,7 @@ void execute(IDocument document) throws BadLocationException { } catch (BadPositionCategoryException e) { // ignore } finally { - if (updateCaret()) { + if (caretPosition != null) { // i.e. updateCaret() document.removePositionUpdater(updater); try { document.removePositionCategory(getCategory()); diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/TextPresentation.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/TextPresentation.java index 42dab5fc166..d7e3cd766d2 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/TextPresentation.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/TextPresentation.java @@ -304,10 +304,7 @@ private void applyStyleRange(StyleRange range, boolean merge) { if (start >= currentEnd) continue; - StyleRange currentCopy= null; - if (end < currentEnd) - currentCopy= (StyleRange)current.clone(); - + StyleRange currentCopy= (end < currentEnd) ? (StyleRange) current.clone() : null; if (start < currentStart) { // Apply style to new default range and add it StyleRange defaultRange= getDefaultStyleRange(); @@ -341,7 +338,7 @@ private void applyStyleRange(StyleRange range, boolean merge) { current.length= Math.min(end, currentEnd) - start; } - if (end < currentEnd) { + if (currentCopy != null) { // i.e. end < currentEnd // Add rest of current range currentCopy.start= end; currentCopy.length= currentEnd - end; diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java index 9f483730bf4..984998fe4bc 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java @@ -2030,21 +2030,23 @@ public void setEventConsumer(IEventConsumer consumer) { @Override public void setIndentPrefixes(String[] indentPrefixes, String contentType) { - int i= -1; - boolean ok= (indentPrefixes != null); - while (ok && ++i < indentPrefixes.length) - ok= (indentPrefixes[i] != null); + boolean ok= false; + if (indentPrefixes != null) { + ok= true; + while (ok && ++i < indentPrefixes.length) { + ok= (indentPrefixes[i] != null); + } + } if (ok) { - - if (fIndentChars == null) + if (fIndentChars == null) { fIndentChars= new HashMap<>(); - + } fIndentChars.put(contentType, indentPrefixes); - - } else if (fIndentChars != null) + } else if (fIndentChars != null) { fIndentChars.remove(contentType); + } } @Override 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 8fbbcfbfc63..f426f8b7ce8 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 @@ -1661,7 +1661,7 @@ public String incrementalComplete() { if (count == 0 && hideWhenNoProposals(false)) return; - if (count == 1 && canAutoInsert(proposals.get(0))) { + if (proposals != null && proposals.size() == 1 && canAutoInsert(proposals.get(0))) { insertProposal(proposals.get(0), (char) 0, 0, fInvocationOffset); hide(); } else { @@ -1793,7 +1793,7 @@ boolean completeCommonPrefix() { if (rightCase.size() == 1) { ICompletionProposal proposal= rightCase.get(0); - if (canAutoInsert(proposal) && rightCasePostfix.length() > 0) { + if (canAutoInsert(proposal) && rightCasePostfix != null && rightCasePostfix.length() > 0) { insertProposal(proposal, (char) 0, 0, fInvocationOffset); hide(); return true; 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 e9d90400718..efab33958ac 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 @@ -189,17 +189,14 @@ public String showContextProposals(final boolean autoActivated) { int offset= fContentAssistSubjectControlAdapter.getSelectedRange().x; IContextInformation[] contexts= computeContextInformation(offset); - int count= (contexts == null ? 0 : contexts.length); - if (count == 1) { - + if (contexts != null && contexts.length == 1) { ContextFrame frame1= createContextFrame(contexts[0], offset); if (isDuplicate(frame1)) validateContextInformation(); else // Show context information directly internalShowContextInfo(frame1); - - } else if (count > 0) { + } else if (contexts != null && contexts.length > 0) { // if any of the proposed context matches any of the contexts on the stack, // assume that one (so, if context info is invoked repeatedly, the current diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/link/LinkedModeUI.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/link/LinkedModeUI.java index c7483e1df3d..0899d785ebc 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/link/LinkedModeUI.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/link/LinkedModeUI.java @@ -950,6 +950,9 @@ private void switchViewer(IDocument oldDoc, IDocument newDoc, LinkedPosition pos } } if (target != fCurrentTarget) { + if (target == null) { + throw new IllegalStateException("target not found"); //$NON-NLS-1$ + } disconnect(); fCurrentTarget= target; target.linkingFocusLost(fFramePosition, target); diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/source/OverviewRuler.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/source/OverviewRuler.java index 74e7ce7a83d..4eb1ef04d72 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/source/OverviewRuler.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/source/OverviewRuler.java @@ -762,7 +762,8 @@ private void doPaint(GC gc) { int annotationEnd= Math.min(p.getOffset() + p.getLength(), visible.getOffset() + visible.getLength()); annotationLength= annotationEnd - annotationOffset; } else { - widgetRegion= extension.modelRange2WidgetRange(new Region(annotationOffset, annotationLength)); + ITextViewerExtension5 ext= extension; + widgetRegion= ext.modelRange2WidgetRange(new Region(annotationOffset, annotationLength)); if (widgetRegion == null) continue; } @@ -774,6 +775,7 @@ private void doPaint(GC gc) { } try { + @SuppressWarnings("null") int startOffset= visible != null ? annotationOffset - visible.getOffset() : widgetRegion.getOffset(); int startLine= textWidget.getLineAtOffset(startOffset); diff --git a/bundles/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionTextStore.java b/bundles/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionTextStore.java index b035a99083d..c5b4f4fd94e 100644 --- a/bundles/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionTextStore.java +++ b/bundles/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionTextStore.java @@ -80,21 +80,17 @@ public ProjectionTextStore(IDocument masterDocument, IMinimalMapping mapping) { fMapping= mapping; } - private void internalError() { - throw new IllegalStateException(); - } - @Override public void set(String contents) { IRegion masterRegion= fMapping.getCoverage(); if (masterRegion == null) - internalError(); + throw new IllegalStateException(); try { fMasterDocument.replace(masterRegion.getOffset(), masterRegion.getLength(), contents); } catch (BadLocationException e) { - internalError(); + throw new IllegalStateException(e); } } @@ -105,7 +101,7 @@ public void replace(int offset, int length, String text) { IRegion masterRegion= fMapping.toOriginRegion(fReusableRegion); fMasterDocument.replace(masterRegion.getOffset(), masterRegion.getLength(), text); } catch (BadLocationException e) { - internalError(); + throw new IllegalStateException(e); } } @@ -120,11 +116,8 @@ public char get(int offset) { int originOffset= fMapping.toOriginOffset(offset); return fMasterDocument.getChar(originOffset); } catch (BadLocationException e) { - internalError(); + throw new IllegalStateException(e); } - - // unreachable - return (char) 0; } @Override @@ -137,10 +130,7 @@ public String get(int offset, int length) { } return buffer.toString(); } catch (BadLocationException e) { - internalError(); + throw new IllegalStateException(e); } - - // unreachable - return null; } } diff --git a/bundles/org.eclipse.text/src/org/eclipse/jface/text/TreeLineTracker.java b/bundles/org.eclipse.text/src/org/eclipse/jface/text/TreeLineTracker.java index 16a02d90e0f..33c794b0682 100755 --- a/bundles/org.eclipse.text/src/org/eclipse/jface/text/TreeLineTracker.java +++ b/bundles/org.eclipse.text/src/org/eclipse/jface/text/TreeLineTracker.java @@ -229,7 +229,7 @@ private Node nodeByOffset(final int offset) throws BadLocationException { Node node= fRoot; while (true) { if (node == null) - fail(offset); + throw new BadLocationException(Integer.toString(offset)); if (remaining < node.offset) { node= node.left; @@ -265,7 +265,7 @@ private int lineByOffset(final int offset) throws BadLocationException { while (true) { if (node == null) - fail(offset); + throw new BadLocationException(Integer.toString(offset)); if (remaining < node.offset) { node= node.left; @@ -299,7 +299,7 @@ private Node nodeByLine(final int line) throws BadLocationException { while (true) { if (node == null) - fail(line); + throw new BadLocationException(Integer.toString(line)); if (remaining == node.line) break; @@ -332,7 +332,7 @@ private int offsetByLine(final int line) throws BadLocationException { while (true) { if (node == null) - fail(line); + throw new BadLocationException(Integer.toString(line)); if (remaining == node.line) return offset + node.offset; @@ -605,7 +605,7 @@ public final void replace(int offset, int length, String text) throws BadLocatio while (true) { if (first == null) - fail(offset); + throw new BadLocationException(Integer.toString(offset)); if (remaining < first.offset) { first= first.left; @@ -653,7 +653,7 @@ private void replaceInternal(Node node, String text, int length, int firstLineDe DelimiterInfo info= text == null ? null : nextDelimiterInfo(text, 0); - if (info == null || info.delimiter == null) { + if (info == null || info.delimiter == null || text == null) { // a) trivial case: insert into a single node, no line mangling int added= text == null ? 0 : text.length(); updateLength(node, added - length); @@ -710,7 +710,7 @@ private void replaceFromTo(Node node, Node last, String text, int length, int fi DelimiterInfo info= text == null ? null : nextDelimiterInfo(text, 0); - if (info == null || info.delimiter == null) { + if (info == null || info.delimiter == null || text == null) { int added= text == null ? 0 : text.length(); // join the two lines if there are no lines added @@ -1044,16 +1044,6 @@ private Node successorDown(Node node) { /* miscellaneous */ - /** - * Throws an exception. - * - * @param offset the illegal character or line offset that caused the exception - * @throws BadLocationException always - */ - private void fail(int offset) throws BadLocationException { - throw new BadLocationException(); - } - /** * Returns the information about the first delimiter found in the given * text starting at the given offset. @@ -1131,7 +1121,7 @@ public final IRegion getLineInformationOfOffset(final int offset) throws BadLoca while (true) { if (node == null) - fail(offset); + throw new BadLocationException(Integer.toString(offset)); if (remaining < node.offset) { node= node.left; @@ -1160,7 +1150,7 @@ public final IRegion getLineInformation(int line) throws BadLocationException { while (true) { if (node == null) - fail(line); + throw new BadLocationException(Integer.toString(line)); if (remaining == node.line) { offset += node.offset; @@ -1191,7 +1181,7 @@ public final IRegion getLineInformation(int line) throws BadLocationException { while (true) { if (node == null) - fail(line); + throw new BadLocationException(Integer.toString(line)); if (remaining == node.line) { offset+= node.offset; diff --git a/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/AbstractDecoratedTextEditor.java b/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/AbstractDecoratedTextEditor.java index eb59acd9e38..9d23f96c6b2 100644 --- a/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/AbstractDecoratedTextEditor.java +++ b/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/AbstractDecoratedTextEditor.java @@ -26,13 +26,33 @@ import java.util.Date; import java.util.Iterator; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.custom.StyledTextPrintOptions; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.Shell; + import org.eclipse.core.commands.operations.IOperationApprover; import org.eclipse.core.commands.operations.IUndoContext; -import org.eclipse.core.filebuffers.FileBuffers; -import org.eclipse.core.filebuffers.IFileBufferStatusCodes; import org.eclipse.core.filesystem.EFS; import org.eclipse.core.filesystem.IFileStore; import org.eclipse.core.filesystem.URIUtil; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; + import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IResource; @@ -40,12 +60,10 @@ import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Platform; + +import org.eclipse.core.filebuffers.FileBuffers; +import org.eclipse.core.filebuffers.IFileBufferStatusCodes; + import org.eclipse.jface.action.Action; import org.eclipse.jface.action.GroupMarker; import org.eclipse.jface.action.IAction; @@ -59,6 +77,11 @@ import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.MessageDialogWithToggle; import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.window.Window; + import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.ITextSelection; @@ -93,23 +116,7 @@ import org.eclipse.jface.text.source.LineNumberRulerColumn; import org.eclipse.jface.text.source.OverviewRuler; import org.eclipse.jface.text.source.SourceViewer; -import org.eclipse.jface.util.PropertyChangeEvent; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.custom.StyledTextPrintOptions; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.FileDialog; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.Shell; + import org.eclipse.ui.IEditorDescriptor; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorPart; @@ -125,12 +132,6 @@ import org.eclipse.ui.actions.WorkspaceModifyOperation; import org.eclipse.ui.dialogs.PreferencesUtil; import org.eclipse.ui.dialogs.SaveAsDialog; -import org.eclipse.ui.editors.text.DefaultEncodingSupport; -import org.eclipse.ui.editors.text.EditorsUI; -import org.eclipse.ui.editors.text.ForwardingDocumentProvider; -import org.eclipse.ui.editors.text.IEncodingSupport; -import org.eclipse.ui.editors.text.IStorageDocumentProvider; -import org.eclipse.ui.editors.text.ITextEditorHelpContextIds; import org.eclipse.ui.ide.FileStoreEditorInput; import org.eclipse.ui.ide.IDEActionFactory; import org.eclipse.ui.ide.IGotoMarker; @@ -153,12 +154,20 @@ import org.eclipse.ui.part.IShowInSource; import org.eclipse.ui.part.IShowInTargetList; import org.eclipse.ui.part.ShowInContext; +import org.eclipse.ui.views.markers.MarkerViewUtil; + import org.eclipse.ui.texteditor.rulers.IColumnSupport; import org.eclipse.ui.texteditor.rulers.IContributedRulerColumn; import org.eclipse.ui.texteditor.rulers.RulerColumnDescriptor; import org.eclipse.ui.texteditor.rulers.RulerColumnPreferenceAdapter; import org.eclipse.ui.texteditor.rulers.RulerColumnRegistry; -import org.eclipse.ui.views.markers.MarkerViewUtil; + +import org.eclipse.ui.editors.text.DefaultEncodingSupport; +import org.eclipse.ui.editors.text.EditorsUI; +import org.eclipse.ui.editors.text.ForwardingDocumentProvider; +import org.eclipse.ui.editors.text.IEncodingSupport; +import org.eclipse.ui.editors.text.IStorageDocumentProvider; +import org.eclipse.ui.editors.text.ITextEditorHelpContextIds; /** @@ -2029,7 +2038,7 @@ private static void revealInEditor(IEditorPart editor, final int offset, final i gotoMarkerTarget= gotoMarker; else gotoMarkerTarget= editor != null ? editor.getAdapter(IGotoMarker.class) : null; - if (gotoMarkerTarget != null) { + if (gotoMarkerTarget != null && editor != null) { final IEditorInput input= editor.getEditorInput(); if (input instanceof IFileEditorInput fileInput) { WorkspaceModifyOperation op= new WorkspaceModifyOperation() { diff --git a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/multiselection/AbstractMultiSelectionHandler.java b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/multiselection/AbstractMultiSelectionHandler.java index 56a69e0484c..30f319950aa 100644 --- a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/multiselection/AbstractMultiSelectionHandler.java +++ b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/multiselection/AbstractMultiSelectionHandler.java @@ -169,7 +169,7 @@ protected void setAnchorRegion(IRegion selection) { private void initAnchorRegion() { IRegion[] regions = getSelectedRegions(); - if ((regions != null && regions.length == 1) || !contains(regions, getAnchorRegion())) { + if (regions != null && (regions.length == 1 || !contains(regions, getAnchorRegion()))) { setAnchorRegion(regions[0]); } } diff --git a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/quickdiff/DocumentLineDiffer.java b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/quickdiff/DocumentLineDiffer.java index 83187bfc92e..9534108eedd 100644 --- a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/quickdiff/DocumentLineDiffer.java +++ b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/quickdiff/DocumentLineDiffer.java @@ -20,6 +20,7 @@ import java.util.LinkedList; import java.util.List; import java.util.ListIterator; +import java.util.Objects; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; @@ -557,7 +558,7 @@ public IStatus run(IProgressMonitor monitor) { // copying the documents as we want to re-inject them later on to become consistent. IDocument right= fRightDocument; // fRightDocument, but not subject to change - IDocument actual= null; // the copy of the actual (right) document + IDocument actual; // the copy of the actual (right) document IDocument reference= null; // the copy of the reference (left) document synchronized (DocumentLineDiffer.this) { @@ -635,6 +636,7 @@ public IStatus run(IProgressMonitor monitor) { break; } } while (true); + Objects.requireNonNull(actual); // fulfilled by break condition } IHashFunction hash= new DJBHashFunction(); diff --git a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java index 36926e08bf6..03699aac85a 100644 --- a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java +++ b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java @@ -4148,13 +4148,14 @@ private void updateDocumentProvider(IEditorInput input) { */ protected void doSetInput(IEditorInput input) throws CoreException { ISaveablesLifecycleListener listener= getSite().getService(ISaveablesLifecycleListener.class); - if (listener == null) + if (listener == null) { fSavable= null; + } if (input == null) { close(isSaveOnCloseNeeded()); - if (fSavable != null) { + if (fSavable != null && listener != null) { listener.handleLifecycleEvent(new SaveablesLifecycleEvent(this, SaveablesLifecycleEvent.POST_CLOSE, getSaveables(), false)); fSavable.disconnectEditor(); fSavable= null; @@ -4162,7 +4163,7 @@ protected void doSetInput(IEditorInput input) throws CoreException { } else { boolean mustSendLifeCycleEvent= false; - if (fSavable != null) { + if (fSavable != null && listener != null) { listener.handleLifecycleEvent(new SaveablesLifecycleEvent(this, SaveablesLifecycleEvent.POST_CLOSE, getSaveables(), false)); fSavable.disconnectEditor(); fSavable= null; @@ -6980,7 +6981,8 @@ protected Annotation findAnnotation(final int offset, final int length, boolean continue; if (forward && p.offset == offset || !forward && p.offset + p.getLength() == offset + length) {// || p.includes(offset)) { - if (containingAnnotation == null || (forward && p.length >= containingAnnotationPosition.length || !forward && p.length >= containingAnnotationPosition.length)) { + if (containingAnnotationPosition == null || (forward && p.length >= containingAnnotationPosition.length + || !forward && p.length >= containingAnnotationPosition.length)) { containingAnnotation= a; containingAnnotationPosition= p; currentAnnotation= p.length == length; diff --git a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/spelling/SpellingCorrectionProcessor.java b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/spelling/SpellingCorrectionProcessor.java index 21145ec4cf5..55f6019b1c8 100644 --- a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/spelling/SpellingCorrectionProcessor.java +++ b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/spelling/SpellingCorrectionProcessor.java @@ -48,9 +48,11 @@ public final class SpellingCorrectionProcessor implements IQuickAssistProcessor @Override public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext quickAssistContext) { ISourceViewer viewer= quickAssistContext.getSourceViewer(); - int documentOffset= quickAssistContext.getOffset(); - - int length= viewer != null ? viewer.getSelectedRange().y : -1; + if (viewer == null) { + return fgNoSuggestionsProposal; + } + int documentOffset = quickAssistContext.getOffset(); + int length = viewer.getSelectedRange().y; TextInvocationContext context= new TextInvocationContext(viewer, documentOffset, length); @@ -62,7 +64,7 @@ public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationC if (proposals.isEmpty()) return fgNoSuggestionsProposal; - return proposals.toArray(new ICompletionProposal[proposals.size()]); + return proposals.toArray(ICompletionProposal[]::new); } private boolean isAtPosition(int offset, Position pos) { diff --git a/tests/org.eclipse.ltk.core.refactoring.tests/src/org/eclipse/ltk/core/refactoring/tests/resource/ResourceRefactoringUndoTests.java b/tests/org.eclipse.ltk.core.refactoring.tests/src/org/eclipse/ltk/core/refactoring/tests/resource/ResourceRefactoringUndoTests.java index ad3fd30fa58..dd69a4654c5 100644 --- a/tests/org.eclipse.ltk.core.refactoring.tests/src/org/eclipse/ltk/core/refactoring/tests/resource/ResourceRefactoringUndoTests.java +++ b/tests/org.eclipse.ltk.core.refactoring.tests/src/org/eclipse/ltk/core/refactoring/tests/resource/ResourceRefactoringUndoTests.java @@ -190,17 +190,16 @@ public void testFolderRenameUndoRedoLTK() throws ExecutionException, CoreExcepti @Test public void testProjectRenameUndoRedoLTK() throws ExecutionException, CoreException { - IProject renamedProject= null; + RefactoringContribution renameContribution= RefactoringCore.getRefactoringContribution(RenameResourceDescriptor.ID); + RenameResourceDescriptor desc= (RenameResourceDescriptor) renameContribution.createDescriptor(); + desc.setResourcePath(fProject.getProject().getFullPath()); + desc.setNewName(TEST_NEWPROJECT_NAME); + PerformRefactoringOperation op= new PerformRefactoringOperation(desc.createRefactoringContext(new RefactoringStatus()), CheckConditionsOperation.ALL_CONDITIONS); + + ProjectSnapshot snap= new ProjectSnapshot(fProject.getProject()); + execute(op); + IProject renamedProject= getWorkspaceRoot().getProject(TEST_NEWPROJECT_NAME); try { - RefactoringContribution renameContribution= RefactoringCore.getRefactoringContribution(RenameResourceDescriptor.ID); - RenameResourceDescriptor desc= (RenameResourceDescriptor) renameContribution.createDescriptor(); - desc.setResourcePath(fProject.getProject().getFullPath()); - desc.setNewName(TEST_NEWPROJECT_NAME); - PerformRefactoringOperation op= new PerformRefactoringOperation(desc.createRefactoringContext(new RefactoringStatus()), CheckConditionsOperation.ALL_CONDITIONS); - - ProjectSnapshot snap= new ProjectSnapshot(fProject.getProject()); - execute(op); - renamedProject= getWorkspaceRoot().getProject(TEST_NEWPROJECT_NAME); assertTrue("Project rename failed", renamedProject.exists()); snap.name= TEST_NEWPROJECT_NAME; assertTrue("Project CONTENT was altered on rename", snap.isValid()); diff --git a/tests/org.eclipse.text.tests/projection/org/eclipse/text/tests/ProjectionDocumentTest.java b/tests/org.eclipse.text.tests/projection/org/eclipse/text/tests/ProjectionDocumentTest.java index 35a176a65fe..5e4bb5649fa 100644 --- a/tests/org.eclipse.text.tests/projection/org/eclipse/text/tests/ProjectionDocumentTest.java +++ b/tests/org.eclipse.text.tests/projection/org/eclipse/text/tests/ProjectionDocumentTest.java @@ -1637,9 +1637,10 @@ private void assertEquals(DocumentEvent expected, DocumentEvent received) { } private void assertSlaveEvents(DocumentEvent[] expected, DocumentEvent[] received) { - if (expected == null) - assertNull(received); - + if (expected == received) { // for example both null + return; + } + assertNotNull(received); assertTrue(expected.length == received.length); for (int i= 0; i < received.length; i++) diff --git a/tests/org.eclipse.text.tests/src/org/eclipse/text/tests/Accessor.java b/tests/org.eclipse.text.tests/src/org/eclipse/text/tests/Accessor.java index b834756b372..262da670f00 100644 --- a/tests/org.eclipse.text.tests/src/org/eclipse/text/tests/Accessor.java +++ b/tests/org.eclipse.text.tests/src/org/eclipse/text/tests/Accessor.java @@ -68,7 +68,7 @@ public Accessor(Object instance, String className, ClassLoader classLoader) { try { fClass= Class.forName(className, true, classLoader); } catch (ClassNotFoundException | ExceptionInInitializerError e) { - fail(e); + throw (AssertionFailedException) new AssertionFailedException(e.getLocalizedMessage()).initCause(e); } } @@ -100,20 +100,20 @@ public Accessor(String className, ClassLoader classLoader, Class[] constructo try { fClass= Class.forName(className, true, classLoader); } catch (ClassNotFoundException | ExceptionInInitializerError e) { - fail(e); + throw (AssertionFailedException) new AssertionFailedException(e.getLocalizedMessage()).initCause(e); } Constructor constructor= null; try { constructor= fClass.getDeclaredConstructor(constructorTypes); } catch (SecurityException | NoSuchMethodException e) { - fail(e); + throw (AssertionFailedException) new AssertionFailedException(e.getLocalizedMessage()).initCause(e); } Assert.isNotNull(constructor); constructor.setAccessible(true); try { fInstance= constructor.newInstance(constructorArgs); } catch (IllegalArgumentException | InvocationTargetException | InstantiationException | IllegalAccessException e) { - fail(e); + throw (AssertionFailedException) new AssertionFailedException(e.getLocalizedMessage()).initCause(e); } } @@ -130,7 +130,7 @@ public Accessor(String className, ClassLoader classLoader) { try { fClass= Class.forName(className, true, classLoader); } catch (ClassNotFoundException | ExceptionInInitializerError e) { - fail(e); + throw (AssertionFailedException) new AssertionFailedException(e.getLocalizedMessage()).initCause(e); } } @@ -163,16 +163,15 @@ public Object invoke(String methodName, Class[] types, Object[] arguments) { try { method= fClass.getDeclaredMethod(methodName, types); } catch (SecurityException | NoSuchMethodException e) { - fail(e); + throw (AssertionFailedException) new AssertionFailedException(e.getLocalizedMessage()).initCause(e); } Assert.isNotNull(method); method.setAccessible(true); try { return method.invoke(fInstance, arguments); } catch (IllegalArgumentException | InvocationTargetException | IllegalAccessException e) { - fail(e); + throw (AssertionFailedException) new AssertionFailedException(e.getLocalizedMessage()).initCause(e); } - return null; } /** @@ -186,7 +185,7 @@ public void set(String fieldName, Object value) { try { field.set(fInstance, value); } catch (IllegalArgumentException | IllegalAccessException e) { - fail(e); + throw (AssertionFailedException) new AssertionFailedException(e.getLocalizedMessage()).initCause(e); } } @@ -201,7 +200,7 @@ public void set(String fieldName, boolean value) { try { field.setBoolean(fInstance, value); } catch (IllegalArgumentException | IllegalAccessException e) { - fail(e); + throw (AssertionFailedException) new AssertionFailedException(e.getLocalizedMessage()).initCause(e); } } @@ -216,7 +215,7 @@ public void set(String fieldName, int value) { try { field.setInt(fInstance, value); } catch (IllegalArgumentException | IllegalAccessException e) { - fail(e); + throw (AssertionFailedException) new AssertionFailedException(e.getLocalizedMessage()).initCause(e); } } @@ -231,10 +230,8 @@ public Object get(String fieldName) { try { return field.get(fInstance); } catch (IllegalArgumentException | IllegalAccessException e) { - fail(e); + throw (AssertionFailedException) new AssertionFailedException(e.getLocalizedMessage()).initCause(e); } - // Unreachable code - return null; } /** @@ -248,10 +245,8 @@ public boolean getBoolean(String fieldName) { try { return field.getBoolean(fInstance); } catch (IllegalArgumentException | IllegalAccessException e) { - fail(e); + throw (AssertionFailedException) new AssertionFailedException(e.getLocalizedMessage()).initCause(e); } - // Unreachable code - return false; } /** @@ -265,21 +260,19 @@ public int getInt(String fieldName) { try { return field.getInt(fInstance); } catch (IllegalArgumentException | IllegalAccessException e) { - fail(e); + throw (AssertionFailedException) new AssertionFailedException(e.getLocalizedMessage()).initCause(e); } - // Unreachable code - return 0; } public Field getField(String fieldName) { - Field field= null; + Field field; try { field= fClass.getDeclaredField(fieldName); + field.setAccessible(true); + return field; } catch (SecurityException | NoSuchFieldException e) { - fail(e); + throw (AssertionFailedException) new AssertionFailedException(e.getLocalizedMessage()).initCause(e); } - field.setAccessible(true); - return field; } private static Class[] getTypes(Object[] objects) { @@ -294,10 +287,4 @@ private static Class[] getTypes(Object[] objects) { } return classes; } - - private void fail(Throwable e) { - AssertionFailedException afe= new AssertionFailedException(e.getLocalizedMessage()); - afe.initCause(e); - throw afe; - } } diff --git a/tests/org.eclipse.text.tests/src/org/eclipse/text/tests/ChildDocumentTest.java b/tests/org.eclipse.text.tests/src/org/eclipse/text/tests/ChildDocumentTest.java index 1d0c8d76b61..a2f526e707e 100644 --- a/tests/org.eclipse.text.tests/src/org/eclipse/text/tests/ChildDocumentTest.java +++ b/tests/org.eclipse.text.tests/src/org/eclipse/text/tests/ChildDocumentTest.java @@ -78,16 +78,16 @@ protected void checkLineInformationConsistency() { assertEquals("Child document store and child line tracker are inconsistent", trackerLines, textLines); for (int i= 0; i < trackerLines; i++) { - IRegion trackerLine= null; - IRegion textLine= null; try { - trackerLine= fDocument.getLineInformation(i); - textLine= textTracker.getLineInformation(i); + IRegion trackerLine = fDocument.getLineInformation(i); + IRegion textLine = textTracker.getLineInformation(i); + assertEquals("Child document store and child line tracker are inconsistent", trackerLine.getOffset(), + textLine.getOffset()); + assertEquals("Child document store and child line tracker are inconsistent", trackerLine.getLength(), + textLine.getLength()); } catch (BadLocationException e) { - assertTrue("BadLocationException thrown", false); + throw new AssertionError("BadLocationException thrown", e); } - assertEquals("Child document store and child line tracker are inconsistent", trackerLine.getOffset(), textLine.getOffset()); - assertEquals("Child document store and child line tracker are inconsistent", trackerLine.getLength(), textLine.getLength()); } } diff --git a/tests/org.eclipse.text.tests/src/org/eclipse/text/tests/link/LinkedModeModelTest.java b/tests/org.eclipse.text.tests/src/org/eclipse/text/tests/link/LinkedModeModelTest.java index c6a823a4ccc..b0088455230 100644 --- a/tests/org.eclipse.text.tests/src/org/eclipse/text/tests/link/LinkedModeModelTest.java +++ b/tests/org.eclipse.text.tests/src/org/eclipse/text/tests/link/LinkedModeModelTest.java @@ -583,6 +583,7 @@ private void assertUnchanged(LinkedPositionGroup actual1, LinkedPositionGroup ac LinkedPosition e_next= i == exp.length ? null : exp[i]; LinkedPosition a_next= i == exp.length ? null : act[i]; + @SuppressWarnings("null") IDocument e_doc= e_prev != null ? e_prev.getDocument() : e_next.getDocument(); if (e_next != null && e_next.getDocument() != e_doc) { // split at document boundaries diff --git a/tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/SWTEventHelper.java b/tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/SWTEventHelper.java index 831af2fbe68..3348ddb5dfc 100755 --- a/tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/SWTEventHelper.java +++ b/tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/SWTEventHelper.java @@ -168,17 +168,19 @@ public static void mouseButtonEvent(Display display, int type, int button, // Returns true if it worked public static boolean performDnD(Widget startItem, Widget dropItem) { - Control startControl = null; + Control startControl; Rectangle boundsStart = null, boundsEnd = null; - if (startItem instanceof TreeItem) { - startControl = ((TreeItem) startItem).getParent(); + if (startItem instanceof TreeItem t) { + startControl = t.getParent(); boundsStart = Display.getCurrent().map(startControl, null, ((TreeItem)startItem).getBounds()); - } else if (startItem instanceof Control) { - startControl = (Control) startItem; + } else if (startItem instanceof Control c) { + startControl = c; boundsStart = Display.getCurrent().map(startControl, null, startControl.getBounds()); + } else { + throw new RuntimeException(startItem.getClass().getName()); } if (dropItem instanceof TreeItem) {