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

Bug 367417 - IndexerPreferenceListener leaks CEditor instance

This commit is contained in:
Anton Leherbauer 2011-12-23 10:45:25 +01:00
parent 42e2c8c5f7
commit 6e1ea34d7c
2 changed files with 51 additions and 4 deletions

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2006, 2010 Wind River Systems, Inc. and others. * Copyright (c) 2006, 2011 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -12,6 +12,7 @@
package org.eclipse.cdt.ui.tests.text; package org.eclipse.cdt.ui.tests.text;
import java.io.File; import java.io.File;
import java.lang.ref.WeakReference;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
@ -110,8 +111,8 @@ public class BasicCEditorTest extends BaseUITestCase {
} }
} }
private static CEditor fEditor; private CEditor fEditor;
private static SourceViewer fSourceViewer; private SourceViewer fSourceViewer;
private ICProject fCProject; private ICProject fCProject;
private IProject fNonCProject; private IProject fNonCProject;
private StyledText fTextWidget; private StyledText fTextWidget;
@ -443,6 +444,24 @@ public class BasicCEditorTest extends BaseUITestCase {
assertTrue(part instanceof CEditor); assertTrue(part instanceof CEditor);
} }
public void testLeakingInstanceAfterClose() throws Exception {
final String file= "/ceditor/src/main.cpp";
fCProject= EditorTestHelper.createCProject("ceditor", "resources/ceditor", false, false);
setUpEditor(file);
fSourceViewer= EditorTestHelper.getSourceViewer(fEditor);
assertTrue(EditorTestHelper.joinReconciler(fSourceViewer, 0, 10000, 100));
WeakReference<CEditor> ref = new WeakReference<CEditor>(fEditor);
EditorTestHelper.closeEditor(fEditor);
fEditor = null;
fSourceViewer = null;
int ngc = 10;
while (ref.get() != null && ngc-- > 0) {
System.gc();
Thread.sleep(200);
}
assertNull("CEditor instance seems to be leaking after close", ref.get());
}
/** /**
* Type characters into the styled text. * Type characters into the styled text.
* *

View file

@ -254,6 +254,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
/* /*
* @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#gotoMarker(org.eclipse.core.resources.IMarker) * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#gotoMarker(org.eclipse.core.resources.IMarker)
*/ */
@Override
public void gotoMarker(IMarker marker) { public void gotoMarker(IMarker marker) {
if (fIsUpdatingMarkerViews) if (fIsUpdatingMarkerViews)
return; return;
@ -433,6 +434,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
/* /*
* @see org.eclipse.jface.text.link.LinkedModeUI$IExitPolicy#doExit(org.eclipse.jface.text.link.LinkedModeModel, org.eclipse.swt.events.VerifyEvent, int, int) * @see org.eclipse.jface.text.link.LinkedModeUI$IExitPolicy#doExit(org.eclipse.jface.text.link.LinkedModeModel, org.eclipse.swt.events.VerifyEvent, int, int)
*/ */
@Override
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) { public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) {
if (fSize == fStack.size() && !isMasked(offset)) { if (fSize == fStack.size() && !isMasked(offset)) {
if (event.character == fExitCharacter) { if (event.character == fExitCharacter) {
@ -497,6 +499,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
/* /*
* @see org.eclipse.jface.text.IPositionUpdater#update(org.eclipse.jface.text.DocumentEvent) * @see org.eclipse.jface.text.IPositionUpdater#update(org.eclipse.jface.text.DocumentEvent)
*/ */
@Override
public void update(DocumentEvent event) { public void update(DocumentEvent event) {
int eventOffset = event.getOffset(); int eventOffset = event.getOffset();
int eventOldLength = event.getLength(); int eventOldLength = event.getLength();
@ -589,6 +592,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
/* /*
* @see org.eclipse.swt.custom.VerifyKeyListener#verifyKey(org.eclipse.swt.events.VerifyEvent) * @see org.eclipse.swt.custom.VerifyKeyListener#verifyKey(org.eclipse.swt.events.VerifyEvent)
*/ */
@Override
public void verifyKey(VerifyEvent event) { public void verifyKey(VerifyEvent event) {
// early pruning to slow down normal typing as little as possible // early pruning to slow down normal typing as little as possible
@ -746,6 +750,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
/* /*
* @see org.eclipse.jface.text.link.ILinkedModeListener#left(org.eclipse.jface.text.link.LinkedModeModel, int) * @see org.eclipse.jface.text.link.ILinkedModeListener#left(org.eclipse.jface.text.link.LinkedModeModel, int)
*/ */
@Override
public void left(LinkedModeModel environment, int flags) { public void left(LinkedModeModel environment, int flags) {
final BracketLevel level = fBracketLevelStack.pop(); final BracketLevel level = fBracketLevelStack.pop();
@ -760,6 +765,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
IDocumentExtension extension = (IDocumentExtension) document; IDocumentExtension extension = (IDocumentExtension) document;
extension.registerPostNotificationReplace(null, new IDocumentExtension.IReplace() { extension.registerPostNotificationReplace(null, new IDocumentExtension.IReplace() {
@Override
public void perform(IDocument d, IDocumentListener owner) { public void perform(IDocument d, IDocumentListener owner) {
if ((level.fFirstPosition.isDeleted || level.fFirstPosition.length == 0) if ((level.fFirstPosition.isDeleted || level.fFirstPosition.length == 0)
&& !level.fSecondPosition.isDeleted && !level.fSecondPosition.isDeleted
@ -789,12 +795,14 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
/* /*
* @see org.eclipse.jface.text.link.ILinkedModeListener#suspend(org.eclipse.jface.text.link.LinkedModeModel) * @see org.eclipse.jface.text.link.ILinkedModeListener#suspend(org.eclipse.jface.text.link.LinkedModeModel)
*/ */
@Override
public void suspend(LinkedModeModel environment) { public void suspend(LinkedModeModel environment) {
} }
/* /*
* @see org.eclipse.jface.text.link.ILinkedModeListener#resume(org.eclipse.jface.text.link.LinkedModeModel, int) * @see org.eclipse.jface.text.link.ILinkedModeListener#resume(org.eclipse.jface.text.link.LinkedModeModel, int)
*/ */
@Override
public void resume(LinkedModeModel environment, int flags) { public void resume(LinkedModeModel environment, int flags) {
} }
} }
@ -809,6 +817,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
/** /**
* @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
*/ */
@Override
public void selectionChanged(SelectionChangedEvent event) { public void selectionChanged(SelectionChangedEvent event) {
// XXX: see https://bugs.eclipse.org/bugs/show_bug.cgi?id=56161 // XXX: see https://bugs.eclipse.org/bugs/show_bug.cgi?id=56161
CEditor.this.selectionChanged(); CEditor.this.selectionChanged();
@ -978,6 +987,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
/* /*
* @see org.eclipse.ui.texteditor.IUpdate#update() * @see org.eclipse.ui.texteditor.IUpdate#update()
*/ */
@Override
public void update() { public void update() {
setEnabled(isEditorInputModifiable()); setEnabled(isEditorInputModifiable());
} }
@ -1181,6 +1191,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
/* /*
* @see org.eclipse.ui.texteditor.IUpdate#update() * @see org.eclipse.ui.texteditor.IUpdate#update()
*/ */
@Override
public void update() { public void update() {
setEnabled(isEditorInputModifiable()); setEnabled(isEditorInputModifiable());
} }
@ -1225,6 +1236,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
private class IndexerPreferenceListener implements IPreferenceChangeListener { private class IndexerPreferenceListener implements IPreferenceChangeListener {
private IProject fProject; private IProject fProject;
@Override
public void preferenceChange(PreferenceChangeEvent event) { public void preferenceChange(PreferenceChangeEvent event) {
if (IndexerPreferences.KEY_INDEX_ON_OPEN.equals(event.getKey())) { if (IndexerPreferences.KEY_INDEX_ON_OPEN.equals(event.getKey())) {
ICElement element= getInputCElement(); ICElement element= getInputCElement();
@ -1398,7 +1410,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
/** The translation unit that was added by the editor to index, or <code>null</code>. */ /** The translation unit that was added by the editor to index, or <code>null</code>. */
private ITranslationUnit fTuAddedToIndex; private ITranslationUnit fTuAddedToIndex;
private IndexerPreferenceListener fIndexerPreferenceListener; private final IndexerPreferenceListener fIndexerPreferenceListener;
private static final Set<String> angularIntroducers = new HashSet<String>(); private static final Set<String> angularIntroducers = new HashSet<String>();
static { static {
@ -1643,6 +1655,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
return getOutlinePage(); return getOutlinePage();
} else if (required == IShowInTargetList.class) { } else if (required == IShowInTargetList.class) {
return new IShowInTargetList() { return new IShowInTargetList() {
@Override
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public String[] getShowInTargetIds() { public String[] getShowInTargetIds() {
return new String[] { IPageLayout.ID_PROJECT_EXPLORER, IPageLayout.ID_OUTLINE, IPageLayout.ID_RES_NAV }; return new String[] { IPageLayout.ID_PROJECT_EXPLORER, IPageLayout.ID_OUTLINE, IPageLayout.ID_RES_NAV };
@ -1656,6 +1669,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
} }
final ISelection selection= ce != null ? new StructuredSelection(ce) : null; final ISelection selection= ce != null ? new StructuredSelection(ce) : null;
return new IShowInSource() { return new IShowInSource() {
@Override
public ShowInContext getShowInContext() { public ShowInContext getShowInContext() {
return new ShowInContext(getEditorInput(), selection); return new ShowInContext(getEditorInput(), selection);
} }
@ -1824,6 +1838,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
if (PreferenceConstants.SCALABILITY_RECONCILER.equals(property) || if (PreferenceConstants.SCALABILITY_RECONCILER.equals(property) ||
PreferenceConstants.SCALABILITY_SYNTAX_COLOR.equals(property)) { PreferenceConstants.SCALABILITY_SYNTAX_COLOR.equals(property)) {
BusyIndicator.showWhile(getSite().getShell().getDisplay(), new Runnable() { BusyIndicator.showWhile(getSite().getShell().getDisplay(), new Runnable() {
@Override
public void run() { public void run() {
setOutlinePageInput(fOutlinePage, getEditorInput()); setOutlinePageInput(fOutlinePage, getEditorInput());
asv.unconfigure(); asv.unconfigure();
@ -1980,6 +1995,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
* React to changed selection in the outline view. * React to changed selection in the outline view.
* @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
*/ */
@Override
public void selectionChanged(SelectionChangedEvent event) { public void selectionChanged(SelectionChangedEvent event) {
ISelection sel = event.getSelection(); ISelection sel = event.getSelection();
if (sel instanceof IStructuredSelection) { if (sel instanceof IStructuredSelection) {
@ -2198,6 +2214,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
*/ */
@Override @Override
public void dispose() { public void dispose() {
fIndexerPreferenceListener.unregister();
updateIndexInclusion(null, true); updateIndexInclusion(null, true);
ISourceViewer sourceViewer = getSourceViewer(); ISourceViewer sourceViewer = getSourceViewer();
@ -2578,6 +2595,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
// bug 291008 - register custom help listener // bug 291008 - register custom help listener
final IWorkbenchHelpSystem helpSystem = PlatformUI.getWorkbench().getHelpSystem(); final IWorkbenchHelpSystem helpSystem = PlatformUI.getWorkbench().getHelpSystem();
parent.addHelpListener(new HelpListener() { parent.addHelpListener(new HelpListener() {
@Override
public void helpRequested(HelpEvent e) { public void helpRequested(HelpEvent e) {
IContextProvider provider = (IContextProvider) CEditor.this.getAdapter(IContextProvider.class); IContextProvider provider = (IContextProvider) CEditor.this.getAdapter(IContextProvider.class);
if (provider != null) { if (provider != null) {
@ -2884,6 +2902,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
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$
fProjectionSupport.setHoverControlCreator(new IInformationControlCreator() { fProjectionSupport.setHoverControlCreator(new IInformationControlCreator() {
@Override
public IInformationControl createInformationControl(Shell shell) { public IInformationControl createInformationControl(Shell shell) {
return new SourceViewerInformationControl(shell, false, getOrientation(), null); return new SourceViewerInformationControl(shell, false, getOrientation(), null);
} }
@ -3163,6 +3182,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
* @see org.eclipse.cdt.internal.ui.text.ICReconcilingListener#aboutToBeReconciled() * @see org.eclipse.cdt.internal.ui.text.ICReconcilingListener#aboutToBeReconciled()
* @since 4.0 * @since 4.0
*/ */
@Override
public void aboutToBeReconciled() { public void aboutToBeReconciled() {
fIsReconciling= true; fIsReconciling= true;
@ -3180,6 +3200,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
* @see org.eclipse.cdt.internal.ui.text.ICReconcilingListener#reconciled(IASTTranslationUnit, boolean, IProgressMonitor) * @see org.eclipse.cdt.internal.ui.text.ICReconcilingListener#reconciled(IASTTranslationUnit, boolean, IProgressMonitor)
* @since 4.0 * @since 4.0
*/ */
@Override
public void reconciled(IASTTranslationUnit ast, boolean force, IProgressMonitor progressMonitor) { public void reconciled(IASTTranslationUnit ast, boolean force, IProgressMonitor progressMonitor) {
fIsReconciling= false; fIsReconciling= false;
@ -3417,6 +3438,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
/* /*
* @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent) * @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent)
*/ */
@Override
public void documentAboutToBeChanged(DocumentEvent event) { public void documentAboutToBeChanged(DocumentEvent event) {
if (fOccurrencesAnnotationUpdaterJob != null) if (fOccurrencesAnnotationUpdaterJob != null)
fOccurrencesAnnotationUpdaterJob.doCancel(); fOccurrencesAnnotationUpdaterJob.doCancel();
@ -3425,12 +3447,14 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
/* /*
* @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent) * @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent)
*/ */
@Override
public void documentChanged(DocumentEvent event) { public void documentChanged(DocumentEvent event) {
} }
/* /*
* @see org.eclipse.jface.text.ITextInputListener#inputDocumentAboutToBeChanged(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.IDocument) * @see org.eclipse.jface.text.ITextInputListener#inputDocumentAboutToBeChanged(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.IDocument)
*/ */
@Override
public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) { public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) {
if (oldInput == null) if (oldInput == null)
return; return;
@ -3441,6 +3465,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
/* /*
* @see org.eclipse.jface.text.ITextInputListener#inputDocumentChanged(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.IDocument) * @see org.eclipse.jface.text.ITextInputListener#inputDocumentChanged(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.IDocument)
*/ */
@Override
public void inputDocumentChanged(IDocument oldInput, IDocument newInput) { public void inputDocumentChanged(IDocument oldInput, IDocument newInput) {
if (newInput == null) if (newInput == null)
return; return;
@ -3536,6 +3561,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
fMarkOccurrenceAnnotations= true; fMarkOccurrenceAnnotations= true;
fPostSelectionListenerWithAST= new ISelectionListenerWithAST() { fPostSelectionListenerWithAST= new ISelectionListenerWithAST() {
@Override
public void selectionChanged(IEditorPart part, ITextSelection selection, IASTTranslationUnit astRoot) { public void selectionChanged(IEditorPart part, ITextSelection selection, IASTTranslationUnit astRoot) {
updateOccurrenceAnnotations(selection, astRoot); updateOccurrenceAnnotations(selection, astRoot);
} }
@ -3544,6 +3570,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
if (forceUpdate && getSelectionProvider() != null) { if (forceUpdate && getSelectionProvider() != null) {
fForcedMarkOccurrencesSelection= getSelectionProvider().getSelection(); fForcedMarkOccurrencesSelection= getSelectionProvider().getSelection();
ASTProvider.getASTProvider().runOnAST(getInputCElement(), ASTProvider.WAIT_NO, getProgressMonitor(), new ASTRunnable() { ASTProvider.getASTProvider().runOnAST(getInputCElement(), ASTProvider.WAIT_NO, getProgressMonitor(), new ASTRunnable() {
@Override
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) throws CoreException { public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) throws CoreException {
updateOccurrenceAnnotations((ITextSelection) fForcedMarkOccurrencesSelection, ast); updateOccurrenceAnnotations((ITextSelection) fForcedMarkOccurrencesSelection, ast);
return Status.OK_STATUS; return Status.OK_STATUS;
@ -3733,6 +3760,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
ICElement inputCElement = getInputCElement(); ICElement inputCElement = getInputCElement();
if (provideAST && inputCElement instanceof ITranslationUnit) { if (provideAST && inputCElement instanceof ITranslationUnit) {
ASTProvider.getASTProvider().runOnAST(inputCElement, ASTProvider.WAIT_ACTIVE_ONLY, getProgressMonitor(), new ASTRunnable() { ASTProvider.getASTProvider().runOnAST(inputCElement, ASTProvider.WAIT_ACTIVE_ONLY, getProgressMonitor(), new ASTRunnable() {
@Override
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) throws CoreException { public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) throws CoreException {
if (ast != null) if (ast != null)
fOverrideIndicatorManager.reconciled(ast, true, getProgressMonitor()); fOverrideIndicatorManager.reconciled(ast, true, getProgressMonitor());