1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Remove unneeded local variables and instanceof checks

new AdaptedSourceViewer was unnecessarily upcast to ISourceViewer
leaving a bunch of null checks and instanceof checks in the rest
of the method. This commit removes the unneeded code.

This extra complication was a result of CDT following JDT, but the JDT
case has much more configurability which meant the extra instanceof
and null checks are needed for JDT case.
This commit is contained in:
Jonah Graham 2025-01-28 14:48:14 -05:00
parent 6fd372066e
commit c795ea8c64

View file

@ -2787,25 +2787,17 @@ public class CEditor extends TextEditor
@Override @Override
protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) { protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
IPreferenceStore store = getPreferenceStore(); IPreferenceStore store = getPreferenceStore();
ISourceViewer sourceViewer = new AdaptedSourceViewer(parent, ruler, getOverviewRuler(), AdaptedSourceViewer cSourceViewer = new AdaptedSourceViewer(parent, ruler, getOverviewRuler(),
isOverviewRulerVisible(), styles, store); isOverviewRulerVisible(), styles, store);
CSourceViewer cSourceViewer = null;
if (sourceViewer instanceof CSourceViewer) {
cSourceViewer = (CSourceViewer) sourceViewer;
}
/* /*
* This is a performance optimization to reduce the computation of * This is a performance optimization to reduce the computation of
* the text presentation triggered by {@link #setVisibleDocument(IDocument)} * the text presentation triggered by {@link #setVisibleDocument(IDocument)}
*/ */
if (cSourceViewer != null && isFoldingEnabled() if (isFoldingEnabled() && (store == null || !store.getBoolean(PreferenceConstants.EDITOR_SHOW_SEGMENTS)))
&& (store == null || !store.getBoolean(PreferenceConstants.EDITOR_SHOW_SEGMENTS)))
cSourceViewer.prepareDelayedProjection(); cSourceViewer.prepareDelayedProjection();
ProjectionViewer projectionViewer = (ProjectionViewer) sourceViewer; fProjectionSupport = new ProjectionSupport(cSourceViewer, getAnnotationAccess(), getSharedColors());
fProjectionSupport = new ProjectionSupport(projectionViewer, getAnnotationAccess(), getSharedColors());
fProjectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.error"); //$NON-NLS-1$ fProjectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.error"); //$NON-NLS-1$
fProjectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.warning"); //$NON-NLS-1$ fProjectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.warning"); //$NON-NLS-1$
fProjectionSupport.addSummarizableAnnotationType("org.eclipse.search.results"); //$NON-NLS-1$ fProjectionSupport.addSummarizableAnnotationType("org.eclipse.search.results"); //$NON-NLS-1$
@ -2816,14 +2808,14 @@ public class CEditor extends TextEditor
fProjectionModelUpdater = CUIPlugin.getDefault().getFoldingStructureProviderRegistry() fProjectionModelUpdater = CUIPlugin.getDefault().getFoldingStructureProviderRegistry()
.getCurrentFoldingProvider(); .getCurrentFoldingProvider();
if (fProjectionModelUpdater != null) if (fProjectionModelUpdater != null)
fProjectionModelUpdater.install(this, projectionViewer); fProjectionModelUpdater.install(this, cSourceViewer);
if (isFoldingEnabled()) if (isFoldingEnabled())
projectionViewer.doOperation(ProjectionViewer.TOGGLE); cSourceViewer.doOperation(ProjectionViewer.TOGGLE);
getSourceViewerDecorationSupport(sourceViewer); getSourceViewerDecorationSupport(cSourceViewer);
return sourceViewer; return cSourceViewer;
} }
/** Outliner context menu Id */ /** Outliner context menu Id */