mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 17:35:35 +02:00
Fix inactive code highlighting race condition and NPE
This commit is contained in:
parent
d017af2e85
commit
013b90d91e
2 changed files with 25 additions and 21 deletions
|
@ -224,10 +224,6 @@ public class CSourceViewerDecorationSupport extends SourceViewerDecorationSuppor
|
|||
* @see org.eclipse.ui.texteditor.SourceViewerDecorationSupport#uninstall()
|
||||
*/
|
||||
public void uninstall() {
|
||||
if (fInactiveCodeHighlighting != null) {
|
||||
fInactiveCodeHighlighting.dispose();
|
||||
fInactiveCodeHighlighting= null;
|
||||
}
|
||||
uninstallLineBackgroundPainter();
|
||||
super.uninstall();
|
||||
}
|
||||
|
@ -252,12 +248,16 @@ public class CSourceViewerDecorationSupport extends SourceViewerDecorationSuppor
|
|||
*/
|
||||
private void uninstallLineBackgroundPainter() {
|
||||
if (fLineBackgroundPainter != null) {
|
||||
if (fInactiveCodeHighlighting != null) {
|
||||
fInactiveCodeHighlighting.uninstall();
|
||||
fInactiveCodeHighlighting= null;
|
||||
}
|
||||
if (fViewer instanceof ITextViewerExtension2) {
|
||||
((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) {
|
||||
installLineBackgroundPainter();
|
||||
if (fLineBackgroundPainter != null) {
|
||||
fInactiveCodeHighlighting= new InactiveCodeHighlighting(fLineBackgroundPainter, INACTIVE_CODE_KEY);
|
||||
fInactiveCodeHighlighting.install(fEditor);
|
||||
fInactiveCodeHighlighting= new InactiveCodeHighlighting(INACTIVE_CODE_KEY);
|
||||
fInactiveCodeHighlighting.install(fEditor, fLineBackgroundPainter);
|
||||
if (refresh) {
|
||||
fInactiveCodeHighlighting.refresh();
|
||||
}
|
||||
|
@ -283,7 +283,7 @@ public class CSourceViewerDecorationSupport extends SourceViewerDecorationSuppor
|
|||
private void hideInactiveCodePositions() {
|
||||
if (fLineBackgroundPainter != null) {
|
||||
if (fInactiveCodeHighlighting != null) {
|
||||
fInactiveCodeHighlighting.dispose();
|
||||
fInactiveCodeHighlighting.uninstall();
|
||||
fInactiveCodeHighlighting= null;
|
||||
}
|
||||
if (!isCLPActive()) {
|
||||
|
|
|
@ -81,10 +81,10 @@ public class InactiveCodeHighlighting implements ICReconcilingListener {
|
|||
private List fInactiveCodePositions= Collections.EMPTY_LIST;
|
||||
|
||||
/**
|
||||
* @param lineBackgroundPainter
|
||||
* Create a highlighter for the given key.
|
||||
* @param highlightKey
|
||||
*/
|
||||
public InactiveCodeHighlighting(LineBackgroundPainter lineBackgroundPainter, String highlightKey) {
|
||||
fLineBackgroundPainter= lineBackgroundPainter;
|
||||
public InactiveCodeHighlighting(String 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 lineBackgroundPainter
|
||||
*/
|
||||
public void install(CEditor editor) {
|
||||
public void install(CEditor editor, LineBackgroundPainter lineBackgroundPainter) {
|
||||
assert fEditor == null;
|
||||
assert editor != null && lineBackgroundPainter != null;
|
||||
fEditor= editor;
|
||||
fLineBackgroundPainter= lineBackgroundPainter;
|
||||
fEditor.addReconcileListener(this);
|
||||
ICElement cElement= fEditor.getInputCElement();
|
||||
if (cElement instanceof ITranslationUnit) {
|
||||
|
@ -136,9 +139,15 @@ public class InactiveCodeHighlighting implements ICReconcilingListener {
|
|||
* Uninstall this highlighting from the editor. Does nothing if already uninstalled.
|
||||
*/
|
||||
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);
|
||||
fInactiveCodePositions= Collections.EMPTY_LIST;
|
||||
fLineBackgroundPainter= null;
|
||||
}
|
||||
if (fEditor != null) {
|
||||
fEditor.removeReconcileListener(this);
|
||||
|
@ -147,11 +156,6 @@ public class InactiveCodeHighlighting implements ICReconcilingListener {
|
|||
}
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
uninstall();
|
||||
fLineBackgroundPainter= null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Force refresh.
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue