1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-10 12:03:16 +02:00

Fix inactive code highlighting race condition and NPE

This commit is contained in:
Anton Leherbauer 2006-08-30 10:07:51 +00:00
parent d017af2e85
commit 013b90d91e
2 changed files with 25 additions and 21 deletions

View file

@ -224,10 +224,6 @@ public class CSourceViewerDecorationSupport extends SourceViewerDecorationSuppor
* @see org.eclipse.ui.texteditor.SourceViewerDecorationSupport#uninstall() * @see org.eclipse.ui.texteditor.SourceViewerDecorationSupport#uninstall()
*/ */
public void uninstall() { public void uninstall() {
if (fInactiveCodeHighlighting != null) {
fInactiveCodeHighlighting.dispose();
fInactiveCodeHighlighting= null;
}
uninstallLineBackgroundPainter(); uninstallLineBackgroundPainter();
super.uninstall(); super.uninstall();
} }
@ -252,12 +248,16 @@ public class CSourceViewerDecorationSupport extends SourceViewerDecorationSuppor
*/ */
private void uninstallLineBackgroundPainter() { private void uninstallLineBackgroundPainter() {
if (fLineBackgroundPainter != null) { if (fLineBackgroundPainter != null) {
if (fInactiveCodeHighlighting != null) {
fInactiveCodeHighlighting.uninstall();
fInactiveCodeHighlighting= null;
}
if (fViewer instanceof ITextViewerExtension2) { if (fViewer instanceof ITextViewerExtension2) {
((ITextViewerExtension2)fViewer).removePainter(fLineBackgroundPainter); ((ITextViewerExtension2)fViewer).removePainter(fLineBackgroundPainter);
fLineBackgroundPainter.deactivate(true);
fLineBackgroundPainter.dispose();
fLineBackgroundPainter = null;
} }
fLineBackgroundPainter.deactivate(true);
fLineBackgroundPainter.dispose();
fLineBackgroundPainter = null;
} }
} }
@ -269,8 +269,8 @@ public class CSourceViewerDecorationSupport extends SourceViewerDecorationSuppor
private void showInactiveCodePositions(boolean refresh) { private void showInactiveCodePositions(boolean refresh) {
installLineBackgroundPainter(); installLineBackgroundPainter();
if (fLineBackgroundPainter != null) { if (fLineBackgroundPainter != null) {
fInactiveCodeHighlighting= new InactiveCodeHighlighting(fLineBackgroundPainter, INACTIVE_CODE_KEY); fInactiveCodeHighlighting= new InactiveCodeHighlighting(INACTIVE_CODE_KEY);
fInactiveCodeHighlighting.install(fEditor); fInactiveCodeHighlighting.install(fEditor, fLineBackgroundPainter);
if (refresh) { if (refresh) {
fInactiveCodeHighlighting.refresh(); fInactiveCodeHighlighting.refresh();
} }
@ -283,7 +283,7 @@ public class CSourceViewerDecorationSupport extends SourceViewerDecorationSuppor
private void hideInactiveCodePositions() { private void hideInactiveCodePositions() {
if (fLineBackgroundPainter != null) { if (fLineBackgroundPainter != null) {
if (fInactiveCodeHighlighting != null) { if (fInactiveCodeHighlighting != null) {
fInactiveCodeHighlighting.dispose(); fInactiveCodeHighlighting.uninstall();
fInactiveCodeHighlighting= null; fInactiveCodeHighlighting= null;
} }
if (!isCLPActive()) { if (!isCLPActive()) {

View file

@ -81,10 +81,10 @@ public class InactiveCodeHighlighting implements ICReconcilingListener {
private List fInactiveCodePositions= Collections.EMPTY_LIST; private List fInactiveCodePositions= Collections.EMPTY_LIST;
/** /**
* @param lineBackgroundPainter * Create a highlighter for the given key.
* @param highlightKey
*/ */
public InactiveCodeHighlighting(LineBackgroundPainter lineBackgroundPainter, String highlightKey) { public InactiveCodeHighlighting(String highlightKey) {
fLineBackgroundPainter= lineBackgroundPainter;
fHighlightKey= highlightKey; fHighlightKey= highlightKey;
} }
@ -116,13 +116,16 @@ public class InactiveCodeHighlighting implements ICReconcilingListener {
} }
/** /**
* Install this highlighting on the given editor. * Install this highlighting on the given editor and line background painter.
* *
* @param editor * @param editor
* @param lineBackgroundPainter
*/ */
public void install(CEditor editor) { public void install(CEditor editor, LineBackgroundPainter lineBackgroundPainter) {
assert fEditor == null; assert fEditor == null;
assert editor != null && lineBackgroundPainter != null;
fEditor= editor; fEditor= editor;
fLineBackgroundPainter= lineBackgroundPainter;
fEditor.addReconcileListener(this); fEditor.addReconcileListener(this);
ICElement cElement= fEditor.getInputCElement(); ICElement cElement= fEditor.getInputCElement();
if (cElement instanceof ITranslationUnit) { if (cElement instanceof ITranslationUnit) {
@ -136,9 +139,15 @@ public class InactiveCodeHighlighting implements ICReconcilingListener {
* Uninstall this highlighting from the editor. Does nothing if already uninstalled. * Uninstall this highlighting from the editor. Does nothing if already uninstalled.
*/ */
public void uninstall() { public void uninstall() {
if (fLineBackgroundPainter != null) { synchronized (fJobLock) {
if (fUpdateJob != null && fUpdateJob.getState() == Job.RUNNING) {
fUpdateJob.cancel();
}
}
if (fLineBackgroundPainter != null && !fLineBackgroundPainter.isDisposed()) {
fLineBackgroundPainter.removeHighlightPositions(fInactiveCodePositions); fLineBackgroundPainter.removeHighlightPositions(fInactiveCodePositions);
fInactiveCodePositions= Collections.EMPTY_LIST; fInactiveCodePositions= Collections.EMPTY_LIST;
fLineBackgroundPainter= null;
} }
if (fEditor != null) { if (fEditor != null) {
fEditor.removeReconcileListener(this); fEditor.removeReconcileListener(this);
@ -147,11 +156,6 @@ public class InactiveCodeHighlighting implements ICReconcilingListener {
} }
} }
public void dispose() {
uninstall();
fLineBackgroundPainter= null;
}
/** /**
* Force refresh. * Force refresh.
*/ */