mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-13 11:15:38 +02:00
Fix for 179671: [Editor] Avoid duplicate parsing when opening a file
Fixes also bug 185709: [Editor] Empty outline when editor is reused
This commit is contained in:
parent
0a32923da7
commit
a678504f0b
8 changed files with 96 additions and 271 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2000, 2006 IBM Corporation and others.
|
* Copyright (c) 2000, 2007 IBM Corporation 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
|
||||||
|
@ -7,6 +7,7 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Corporation - initial API and implementation
|
* IBM Corporation - initial API and implementation
|
||||||
|
* Anton Leherbauer (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.model;
|
package org.eclipse.cdt.internal.core.model;
|
||||||
|
|
||||||
|
@ -51,34 +52,24 @@ public class ReconcileWorkingCopyOperation extends CModelOperation {
|
||||||
CElementDeltaBuilder deltaBuilder = null;
|
CElementDeltaBuilder deltaBuilder = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// create the delta builder (this remembers the current content of the cu)
|
if (!wasConsistent || forceProblemDetection || fComputeAST) {
|
||||||
if (!wasConsistent){
|
// create the delta builder (this remembers the current content of the tu)
|
||||||
deltaBuilder = new CElementDeltaBuilder(workingCopy);
|
deltaBuilder = new CElementDeltaBuilder(workingCopy);
|
||||||
|
|
||||||
// update the element infos with the content of the working copy
|
// update the element infos with the content of the working copy
|
||||||
if (fComputeAST) {
|
|
||||||
fAST= workingCopy.makeConsistent(fComputeAST, fMonitor);
|
fAST= workingCopy.makeConsistent(fComputeAST, fMonitor);
|
||||||
} else {
|
|
||||||
workingCopy.makeConsistent(fMonitor);
|
|
||||||
}
|
|
||||||
deltaBuilder.buildDeltas();
|
deltaBuilder.buildDeltas();
|
||||||
|
|
||||||
// register the deltas
|
// register the deltas
|
||||||
if (deltaBuilder != null){
|
if (deltaBuilder.delta != null) {
|
||||||
if ((deltaBuilder.delta != null) && (deltaBuilder.delta.getAffectedChildren().length > 0)) {
|
|
||||||
addReconcileDelta(workingCopy, deltaBuilder.delta);
|
addReconcileDelta(workingCopy, deltaBuilder.delta);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fMonitor != null) fMonitor.worked(2);
|
if (fMonitor != null) fMonitor.worked(2);
|
||||||
|
|
||||||
// force problem detection? - if structure was consistent
|
|
||||||
if (forceProblemDetection && wasConsistent){
|
|
||||||
if (fMonitor != null && fMonitor.isCanceled()) return;
|
|
||||||
}
|
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
if (fMonitor != null) fMonitor.done();
|
if (fMonitor != null) fMonitor.done();
|
||||||
}
|
}
|
||||||
|
|
|
@ -490,11 +490,11 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void makeConsistent(IProgressMonitor monitor, boolean forced) throws CModelException {
|
public void makeConsistent(IProgressMonitor monitor, boolean forced) throws CModelException {
|
||||||
makeConsistent(false, monitor);
|
makeConsistent(forced, monitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IASTTranslationUnit makeConsistent(boolean computeAST, IProgressMonitor monitor) throws CModelException {
|
protected IASTTranslationUnit makeConsistent(boolean computeAST, IProgressMonitor monitor) throws CModelException {
|
||||||
if (isConsistent()) {
|
if (!computeAST && isConsistent()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ package org.eclipse.cdt.internal.ui.editor;
|
||||||
import org.eclipse.core.runtime.Assert;
|
import org.eclipse.core.runtime.Assert;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.ui.IPartListener2;
|
import org.eclipse.ui.IPartListener2;
|
||||||
import org.eclipse.ui.IWindowListener;
|
import org.eclipse.ui.IWindowListener;
|
||||||
import org.eclipse.ui.IWorkbenchPart;
|
import org.eclipse.ui.IWorkbenchPart;
|
||||||
|
@ -298,6 +299,9 @@ public final class ASTProvider {
|
||||||
if (cElement == null)
|
if (cElement == null)
|
||||||
return null;
|
return null;
|
||||||
Assert.isTrue(cElement instanceof ITranslationUnit);
|
Assert.isTrue(cElement instanceof ITranslationUnit);
|
||||||
|
if (waitFlag == WAIT_ACTIVE_ONLY && !isActive((ITranslationUnit)cElement)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return fCache.getAST((ITranslationUnit)cElement, index, waitFlag != WAIT_NO, progressMonitor);
|
return fCache.getAST((ITranslationUnit)cElement, index, waitFlag != WAIT_NO, progressMonitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -326,6 +330,9 @@ public final class ASTProvider {
|
||||||
public IStatus runOnAST(ICElement cElement, WAIT_FLAG waitFlag, IProgressMonitor monitor,
|
public IStatus runOnAST(ICElement cElement, WAIT_FLAG waitFlag, IProgressMonitor monitor,
|
||||||
ASTCache.ASTRunnable astRunnable) {
|
ASTCache.ASTRunnable astRunnable) {
|
||||||
Assert.isTrue(cElement instanceof ITranslationUnit);
|
Assert.isTrue(cElement instanceof ITranslationUnit);
|
||||||
|
if (waitFlag == WAIT_ACTIVE_ONLY && !isActive((ITranslationUnit)cElement)) {
|
||||||
|
return Status.CANCEL_STATUS;
|
||||||
|
}
|
||||||
return fCache.runOnAST((ITranslationUnit)cElement, waitFlag != WAIT_NO, monitor, astRunnable);
|
return fCache.runOnAST((ITranslationUnit)cElement, waitFlag != WAIT_NO, monitor, astRunnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2002, 2006 QNX Software Systems and others.
|
* Copyright (c) 2002, 2007 QNX Software Systems 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
|
||||||
|
@ -7,6 +7,7 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX Software Systems - Initial API and implementation
|
* QNX Software Systems - Initial API and implementation
|
||||||
|
* Anton Leherbauer (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.editor;
|
package org.eclipse.cdt.internal.ui.editor;
|
||||||
|
|
||||||
|
@ -14,6 +15,16 @@ import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.jface.util.IPropertyChangeListener;
|
||||||
|
import org.eclipse.jface.util.PropertyChangeEvent;
|
||||||
|
import org.eclipse.jface.viewers.ISelection;
|
||||||
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||||
|
import org.eclipse.jface.viewers.StructuredSelection;
|
||||||
|
import org.eclipse.jface.viewers.TreeViewer;
|
||||||
|
import org.eclipse.jface.viewers.Viewer;
|
||||||
|
import org.eclipse.ui.IWorkbenchPartSite;
|
||||||
|
import org.eclipse.ui.progress.PendingUpdateAdapter;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.CModelException;
|
import org.eclipse.cdt.core.model.CModelException;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.core.model.ElementChangedEvent;
|
import org.eclipse.cdt.core.model.ElementChangedEvent;
|
||||||
|
@ -22,27 +33,13 @@ import org.eclipse.cdt.core.model.ICElementDelta;
|
||||||
import org.eclipse.cdt.core.model.IElementChangedListener;
|
import org.eclipse.cdt.core.model.IElementChangedListener;
|
||||||
import org.eclipse.cdt.core.model.ISourceRange;
|
import org.eclipse.cdt.core.model.ISourceRange;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
|
import org.eclipse.cdt.ui.PreferenceConstants;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.model.CShiftData;
|
import org.eclipse.cdt.internal.core.model.CShiftData;
|
||||||
import org.eclipse.cdt.internal.core.model.SourceManipulation;
|
import org.eclipse.cdt.internal.core.model.SourceManipulation;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.BaseCElementContentProvider;
|
import org.eclipse.cdt.internal.ui.BaseCElementContentProvider;
|
||||||
import org.eclipse.cdt.internal.ui.util.StringMatcher;
|
import org.eclipse.cdt.internal.ui.util.StringMatcher;
|
||||||
import org.eclipse.cdt.ui.PreferenceConstants;
|
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
|
||||||
import org.eclipse.core.runtime.IStatus;
|
|
||||||
import org.eclipse.core.runtime.Status;
|
|
||||||
import org.eclipse.jface.util.IPropertyChangeListener;
|
|
||||||
import org.eclipse.jface.util.PropertyChangeEvent;
|
|
||||||
import org.eclipse.jface.viewers.AbstractTreeViewer;
|
|
||||||
import org.eclipse.jface.viewers.ISelection;
|
|
||||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
|
||||||
import org.eclipse.jface.viewers.StructuredSelection;
|
|
||||||
import org.eclipse.jface.viewers.TreeViewer;
|
|
||||||
import org.eclipse.jface.viewers.Viewer;
|
|
||||||
import org.eclipse.ui.IWorkbenchPartSite;
|
|
||||||
import org.eclipse.ui.progress.DeferredTreeContentManager;
|
|
||||||
import org.eclipse.ui.progress.IElementCollector;
|
|
||||||
import org.eclipse.ui.progress.PendingUpdateAdapter;
|
|
||||||
import org.eclipse.ui.progress.WorkbenchJob;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages contents of the outliner.
|
* Manages contents of the outliner.
|
||||||
|
@ -64,19 +61,6 @@ public class CContentOutlinerProvider extends BaseCElementContentProvider {
|
||||||
/** Filter for files to outline. */
|
/** Filter for files to outline. */
|
||||||
private StringMatcher filter = new StringMatcher("*", true, false); //$NON-NLS-1$
|
private StringMatcher filter = new StringMatcher("*", true, false); //$NON-NLS-1$
|
||||||
|
|
||||||
/**
|
|
||||||
* Remote content manager to retrieve content in the background.
|
|
||||||
*/
|
|
||||||
private DeferredTreeContentManager fManager;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* We only want to use the DeferredContentManager, the first time
|
|
||||||
* because the Outliner is initialize in the UI thread. So to not block
|
|
||||||
* the UI thread we deferred, after it is not necessary the reconciler is
|
|
||||||
* running in a separate thread not affecting the UI.
|
|
||||||
*/
|
|
||||||
private boolean fUseContentManager = false;
|
|
||||||
|
|
||||||
public CContentOutlinerProvider(TreeViewer viewer) {
|
public CContentOutlinerProvider(TreeViewer viewer) {
|
||||||
this(viewer, null);
|
this(viewer, null);
|
||||||
}
|
}
|
||||||
|
@ -91,68 +75,6 @@ public class CContentOutlinerProvider extends BaseCElementContentProvider {
|
||||||
super(true, true);
|
super(true, true);
|
||||||
treeViewer = viewer;
|
treeViewer = viewer;
|
||||||
setIncludesGrouping(PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.OUTLINE_GROUP_INCLUDES));
|
setIncludesGrouping(PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.OUTLINE_GROUP_INCLUDES));
|
||||||
fManager = createContentManager(viewer, site);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Subclass of DeferredTreeContentManager used to refresh
|
|
||||||
* the outline when the "group includes" setting is enabled.
|
|
||||||
*/
|
|
||||||
class DeferredTreeCContentManager extends DeferredTreeContentManager {
|
|
||||||
|
|
||||||
public DeferredTreeCContentManager(AbstractTreeViewer viewer, IWorkbenchPartSite site) {
|
|
||||||
super(CContentOutlinerProvider.this, viewer, site);
|
|
||||||
}
|
|
||||||
|
|
||||||
public DeferredTreeCContentManager(AbstractTreeViewer viewer) {
|
|
||||||
super(CContentOutlinerProvider.this, viewer);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected IElementCollector createElementCollector(final Object parent,
|
|
||||||
final PendingUpdateAdapter placeholder) {
|
|
||||||
|
|
||||||
// Return a special element collector when the parent
|
|
||||||
// is the translation unit. In that case we need to
|
|
||||||
// refresh the outline when all the content has become
|
|
||||||
// available.
|
|
||||||
if (!(parent instanceof ITranslationUnit)) {
|
|
||||||
return super.createElementCollector(parent, placeholder);
|
|
||||||
}
|
|
||||||
return new IElementCollector() {
|
|
||||||
public void add(Object element, IProgressMonitor monitor) {
|
|
||||||
add(new Object[] { element }, monitor);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Object[] elements, IProgressMonitor monitor) {
|
|
||||||
addChildren(parent, elements, monitor);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void done() {
|
|
||||||
runClearPlaceholderJob(placeholder);
|
|
||||||
// runClearPlaceholderJob uses a WorkbenchJob and contentUpdated
|
|
||||||
// executes via asyncExec(). There can be race conditions if we
|
|
||||||
// don't wrap contentUpdated in a job.
|
|
||||||
if (CContentOutlinerProvider.this.fIncludesGrouping) {
|
|
||||||
WorkbenchJob job = new WorkbenchJob("") { //$NON-NLS-1$
|
|
||||||
|
|
||||||
public IStatus runInUIThread(IProgressMonitor monitor) {
|
|
||||||
contentUpdated();
|
|
||||||
return Status.OK_STATUS;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
job.setSystem(true);
|
|
||||||
job.schedule();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected DeferredTreeContentManager createContentManager(TreeViewer viewer, IWorkbenchPartSite site) {
|
|
||||||
if (site == null) {
|
|
||||||
return new DeferredTreeCContentManager(viewer);
|
|
||||||
}
|
|
||||||
return new DeferredTreeCContentManager(viewer, site);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -229,37 +151,30 @@ public class CContentOutlinerProvider extends BaseCElementContentProvider {
|
||||||
PreferenceConstants.getPreferenceStore().removePropertyChangeListener(fPropertyListener);
|
PreferenceConstants.getPreferenceStore().removePropertyChangeListener(fPropertyListener);
|
||||||
fPropertyListener = null;
|
fPropertyListener = null;
|
||||||
}
|
}
|
||||||
if (root != null) {
|
|
||||||
fManager.cancel(root);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
|
* @see org.eclipse.cdt.internal.ui.BaseCElementContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
|
||||||
* java.lang.Object, java.lang.Object)
|
|
||||||
*/
|
*/
|
||||||
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
||||||
boolean isTU = newInput instanceof ITranslationUnit;
|
boolean isTU = newInput instanceof ITranslationUnit;
|
||||||
|
|
||||||
if (isTU && fListener == null) {
|
if (isTU) {
|
||||||
fUseContentManager = true;
|
|
||||||
if (root != null) {
|
|
||||||
fManager.cancel(root);
|
|
||||||
}
|
|
||||||
root = (ITranslationUnit) newInput;
|
root = (ITranslationUnit) newInput;
|
||||||
fListener = new ElementChangedListener();
|
if (fListener == null) {
|
||||||
|
fListener= new ElementChangedListener();
|
||||||
CoreModel.getDefault().addElementChangedListener(fListener);
|
CoreModel.getDefault().addElementChangedListener(fListener);
|
||||||
fPropertyListener = new PropertyListener();
|
fPropertyListener= new PropertyListener();
|
||||||
PreferenceConstants.getPreferenceStore().addPropertyChangeListener(
|
PreferenceConstants.getPreferenceStore().addPropertyChangeListener(fPropertyListener);
|
||||||
fPropertyListener);
|
|
||||||
} else if (!isTU && fListener != null) {
|
|
||||||
fUseContentManager = false;
|
|
||||||
CoreModel.getDefault().removeElementChangedListener(fListener);
|
|
||||||
fListener = null;
|
|
||||||
root = null;
|
|
||||||
if (oldInput != null) {
|
|
||||||
fManager.cancel(oldInput);
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (fListener != null) {
|
||||||
|
CoreModel.getDefault().removeElementChangedListener(fListener);
|
||||||
|
PreferenceConstants.getPreferenceStore().removePropertyChangeListener(fPropertyListener);
|
||||||
|
fListener= null;
|
||||||
|
fPropertyListener= null;
|
||||||
|
}
|
||||||
|
root= null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,9 +184,11 @@ public class CContentOutlinerProvider extends BaseCElementContentProvider {
|
||||||
public Object[] getChildren(Object element) {
|
public Object[] getChildren(Object element) {
|
||||||
Object[] children = null;
|
Object[] children = null;
|
||||||
// Use the deferred manager for the first time (when parsing)
|
// Use the deferred manager for the first time (when parsing)
|
||||||
if (fUseContentManager && element instanceof ITranslationUnit) {
|
if (element instanceof ITranslationUnit) {
|
||||||
children = fManager.getChildren(element);
|
ITranslationUnit unit= (ITranslationUnit)element;
|
||||||
fUseContentManager = false;
|
if (!unit.isOpen()) {
|
||||||
|
children= new Object[] { new PendingUpdateAdapter() };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (children == null) {
|
if (children == null) {
|
||||||
children = super.getChildren(element);
|
children = super.getChildren(element);
|
||||||
|
@ -292,9 +209,6 @@ public class CContentOutlinerProvider extends BaseCElementContentProvider {
|
||||||
* @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
|
* @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
|
||||||
*/
|
*/
|
||||||
public boolean hasChildren(Object element) {
|
public boolean hasChildren(Object element) {
|
||||||
if (fUseContentManager) {
|
|
||||||
return fManager.mayHaveChildren(element);
|
|
||||||
}
|
|
||||||
return super.hasChildren(element);
|
return super.hasChildren(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,6 +74,7 @@ import org.eclipse.jface.text.source.IAnnotationModel;
|
||||||
import org.eclipse.jface.text.source.ICharacterPairMatcher;
|
import org.eclipse.jface.text.source.ICharacterPairMatcher;
|
||||||
import org.eclipse.jface.text.source.IOverviewRuler;
|
import org.eclipse.jface.text.source.IOverviewRuler;
|
||||||
import org.eclipse.jface.text.source.ISourceViewer;
|
import org.eclipse.jface.text.source.ISourceViewer;
|
||||||
|
import org.eclipse.jface.text.source.ISourceViewerExtension2;
|
||||||
import org.eclipse.jface.text.source.IVerticalRuler;
|
import org.eclipse.jface.text.source.IVerticalRuler;
|
||||||
import org.eclipse.jface.text.source.SourceViewerConfiguration;
|
import org.eclipse.jface.text.source.SourceViewerConfiguration;
|
||||||
import org.eclipse.jface.text.source.projection.ProjectionAnnotationModel;
|
import org.eclipse.jface.text.source.projection.ProjectionAnnotationModel;
|
||||||
|
@ -138,7 +139,6 @@ import org.eclipse.cdt.core.IPositionConverter;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage;
|
import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage;
|
||||||
import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants;
|
import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants;
|
||||||
import org.eclipse.cdt.core.index.IIndex;
|
|
||||||
import org.eclipse.cdt.core.model.CModelException;
|
import org.eclipse.cdt.core.model.CModelException;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
|
@ -156,8 +156,6 @@ import org.eclipse.cdt.ui.actions.OpenViewActionGroup;
|
||||||
import org.eclipse.cdt.ui.text.ICPartitions;
|
import org.eclipse.cdt.ui.text.ICPartitions;
|
||||||
import org.eclipse.cdt.ui.text.folding.ICFoldingStructureProvider;
|
import org.eclipse.cdt.ui.text.folding.ICFoldingStructureProvider;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.corext.util.SimplePositionTracker;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.CPluginImages;
|
import org.eclipse.cdt.internal.ui.CPluginImages;
|
||||||
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
|
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
|
||||||
import org.eclipse.cdt.internal.ui.IContextMenuConstants;
|
import org.eclipse.cdt.internal.ui.IContextMenuConstants;
|
||||||
|
@ -186,9 +184,9 @@ import org.eclipse.cdt.internal.ui.util.CUIHelp;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* C specific text editor.
|
* C/C++ source editor.
|
||||||
*/
|
*/
|
||||||
public class CEditor extends TextEditor implements ISelectionChangedListener, IReconcilingParticipant, ICReconcilingListener {
|
public class CEditor extends TextEditor implements ISelectionChangedListener, ICReconcilingListener {
|
||||||
|
|
||||||
class AdaptedSourceViewer extends CSourceViewer {
|
class AdaptedSourceViewer extends CSourceViewer {
|
||||||
|
|
||||||
|
@ -1159,7 +1157,22 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IR
|
||||||
* @see org.eclipse.ui.texteditor.AbstractTextEditor#doSetInput(org.eclipse.ui.IEditorInput)
|
* @see org.eclipse.ui.texteditor.AbstractTextEditor#doSetInput(org.eclipse.ui.IEditorInput)
|
||||||
*/
|
*/
|
||||||
protected void doSetInput(IEditorInput input) throws CoreException {
|
protected void doSetInput(IEditorInput input) throws CoreException {
|
||||||
|
boolean reuse= getEditorInput() != null;
|
||||||
|
|
||||||
super.doSetInput(input);
|
super.doSetInput(input);
|
||||||
|
|
||||||
|
if (reuse) {
|
||||||
|
// in case language changed, need to reconfigure the viewer
|
||||||
|
ISourceViewer viewer= getSourceViewer();
|
||||||
|
if (viewer instanceof ISourceViewerExtension2) {
|
||||||
|
ISourceViewerExtension2 viewerExt2= (ISourceViewerExtension2)viewer;
|
||||||
|
viewerExt2.unconfigure();
|
||||||
|
CSourceViewerConfiguration cConfig= (CSourceViewerConfiguration)getSourceViewerConfiguration();
|
||||||
|
cConfig.resetScanners();
|
||||||
|
viewer.configure(cConfig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setOutlinePageInput(fOutlinePage, input);
|
setOutlinePageInput(fOutlinePage, input);
|
||||||
|
|
||||||
if (fProjectionModelUpdater != null) {
|
if (fProjectionModelUpdater != null) {
|
||||||
|
@ -1548,7 +1561,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IR
|
||||||
* @param element Element to select.
|
* @param element Element to select.
|
||||||
*/
|
*/
|
||||||
public void setSelection(ICElement element) {
|
public void setSelection(ICElement element) {
|
||||||
if (element instanceof ISourceReference) {
|
if (element instanceof ISourceReference && !(element instanceof ITranslationUnit)) {
|
||||||
ISourceReference reference = (ISourceReference) element;
|
ISourceReference reference = (ISourceReference) element;
|
||||||
// set hightlight range
|
// set hightlight range
|
||||||
setSelection(reference, true);
|
setSelection(reference, true);
|
||||||
|
@ -2471,51 +2484,6 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IR
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* @see org.eclipse.cdt.internal.ui.editor.IReconcilingParticipant#reconciled()
|
|
||||||
*/
|
|
||||||
public void reconciled(boolean somethingHasChanged) {
|
|
||||||
if (getSourceViewer() == null || getSourceViewer().getTextWidget() == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// this method must be called in a background thread
|
|
||||||
assert getSourceViewer().getTextWidget().getDisplay().getThread() != Thread.currentThread();
|
|
||||||
|
|
||||||
if (fReconcilingListeners.size() > 0) {
|
|
||||||
// create AST and notify ICReconcilingListeners
|
|
||||||
ICElement cElement= getInputCElement();
|
|
||||||
if (cElement == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
aboutToBeReconciled();
|
|
||||||
|
|
||||||
// track changes to the document while parsing
|
|
||||||
IDocument doc= getDocumentProvider().getDocument(getEditorInput());
|
|
||||||
SimplePositionTracker positionTracker= new SimplePositionTracker();
|
|
||||||
positionTracker.startTracking(doc);
|
|
||||||
|
|
||||||
ASTProvider astProvider= CUIPlugin.getDefault().getASTProvider();
|
|
||||||
IIndex index;
|
|
||||||
try {
|
|
||||||
index = CCorePlugin.getIndexManager().getIndex(cElement.getCProject());
|
|
||||||
index.acquireReadLock();
|
|
||||||
} catch (CoreException e) {
|
|
||||||
CUIPlugin.getDefault().log(e);
|
|
||||||
return;
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
IASTTranslationUnit ast= astProvider.createAST(cElement, index, null);
|
|
||||||
reconciled(ast, positionTracker, null);
|
|
||||||
} finally {
|
|
||||||
index.releaseReadLock();
|
|
||||||
positionTracker.stopTracking();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#collectContextMenuPreferencePages()
|
* @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#collectContextMenuPreferencePages()
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2004, 2006 IBM Corporation and others.
|
* Copyright (c) 2004, 2007 IBM Corporation 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
|
||||||
|
@ -15,6 +15,7 @@ package org.eclipse.cdt.internal.ui.editor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface of an object participating in reconciling.
|
* Interface of an object participating in reconciling.
|
||||||
|
* @deprecated in favour of {@link org.eclipse.cdt.internal.ui.text.ICReconcilingListener}
|
||||||
*/
|
*/
|
||||||
public interface IReconcilingParticipant {
|
public interface IReconcilingParticipant {
|
||||||
|
|
||||||
|
|
|
@ -33,8 +33,6 @@ import org.eclipse.cdt.ui.IWorkingCopyManager;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.model.CModelManager;
|
import org.eclipse.cdt.internal.core.model.CModelManager;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.editor.IReconcilingParticipant;
|
|
||||||
|
|
||||||
|
|
||||||
public class CReconcilingStrategy implements IReconcilingStrategy, IReconcilingStrategyExtension {
|
public class CReconcilingStrategy implements IReconcilingStrategy, IReconcilingStrategyExtension {
|
||||||
|
|
||||||
|
@ -73,6 +71,7 @@ public class CReconcilingStrategy implements IReconcilingStrategy, IReconcilingS
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @see org.eclipse.jface.text.reconciler.IReconcilingStrategy#reconcile(org.eclipse.jface.text.reconciler.DirtyRegion, org.eclipse.jface.text.IRegion)
|
* @see org.eclipse.jface.text.reconciler.IReconcilingStrategy#reconcile(org.eclipse.jface.text.reconciler.DirtyRegion, org.eclipse.jface.text.IRegion)
|
||||||
|
* Called for incremental reconciler only - currently not used (no shift deltas)
|
||||||
*/
|
*/
|
||||||
public void reconcile(DirtyRegion dirtyRegion, IRegion region) {
|
public void reconcile(DirtyRegion dirtyRegion, IRegion region) {
|
||||||
// consistent data needs not further checks !
|
// consistent data needs not further checks !
|
||||||
|
@ -114,13 +113,13 @@ public class CReconcilingStrategy implements IReconcilingStrategy, IReconcilingS
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reconcile(final boolean initialReconcile) {
|
private void reconcile(final boolean initialReconcile) {
|
||||||
|
boolean computeAST= fEditor instanceof ICReconcilingListener;
|
||||||
IASTTranslationUnit ast= null;
|
IASTTranslationUnit ast= null;
|
||||||
IWorkingCopy workingCopy= fManager.getWorkingCopy(fEditor.getEditorInput());
|
IWorkingCopy workingCopy= fManager.getWorkingCopy(fEditor.getEditorInput());
|
||||||
if (workingCopy == null) {
|
if (workingCopy == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
final boolean computeAST= initialReconcile || CUIPlugin.getDefault().getASTProvider().isActive(workingCopy);
|
|
||||||
// reconcile
|
// reconcile
|
||||||
synchronized (workingCopy) {
|
synchronized (workingCopy) {
|
||||||
ast= workingCopy.reconcile(computeAST, true, fProgressMonitor);
|
ast= workingCopy.reconcile(computeAST, true, fProgressMonitor);
|
||||||
|
@ -131,18 +130,10 @@ public class CReconcilingStrategy implements IReconcilingStrategy, IReconcilingS
|
||||||
IStatus status= new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, IStatus.OK, "Error in CDT UI during reconcile", e); //$NON-NLS-1$
|
IStatus status= new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, IStatus.OK, "Error in CDT UI during reconcile", e); //$NON-NLS-1$
|
||||||
CUIPlugin.getDefault().log(status);
|
CUIPlugin.getDefault().log(status);
|
||||||
} finally {
|
} finally {
|
||||||
if (fEditor instanceof ICReconcilingListener) {
|
if (computeAST) {
|
||||||
IIndex index= null;
|
IIndex index= null;
|
||||||
if (ast != null) {
|
if (ast != null) {
|
||||||
index= ast.getIndex();
|
index= ast.getIndex();
|
||||||
if (index != null) {
|
|
||||||
try {
|
|
||||||
index.acquireReadLock();
|
|
||||||
} catch (InterruptedException exc) {
|
|
||||||
ast= null;
|
|
||||||
index= null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
((ICReconcilingListener)fEditor).reconciled(ast, null, fProgressMonitor);
|
((ICReconcilingListener)fEditor).reconciled(ast, null, fProgressMonitor);
|
||||||
|
@ -152,13 +143,6 @@ public class CReconcilingStrategy implements IReconcilingStrategy, IReconcilingS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fProgressMonitor != null && fProgressMonitor.isCanceled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (ast == null && fEditor instanceof IReconcilingParticipant && workingCopy.exists()) {
|
|
||||||
IReconcilingParticipant p= (IReconcilingParticipant) fEditor;
|
|
||||||
p.reconciled(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,9 +58,7 @@ import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.model.CModelException;
|
import org.eclipse.cdt.core.model.CModelException;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.core.model.ElementChangedEvent;
|
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.model.ICElementDelta;
|
|
||||||
import org.eclipse.cdt.core.model.IElementChangedListener;
|
import org.eclipse.cdt.core.model.IElementChangedListener;
|
||||||
import org.eclipse.cdt.core.model.IMember;
|
import org.eclipse.cdt.core.model.IMember;
|
||||||
import org.eclipse.cdt.core.model.IParent;
|
import org.eclipse.cdt.core.model.IParent;
|
||||||
|
@ -104,13 +102,16 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
||||||
* @see org.eclipse.cdt.internal.ui.text.ICReconcilingListener#reconciled(org.eclipse.cdt.core.dom.ast.IASTTranslationUnit, org.eclipse.cdt.core.IPositionConverter, org.eclipse.core.runtime.IProgressMonitor)
|
* @see org.eclipse.cdt.internal.ui.text.ICReconcilingListener#reconciled(org.eclipse.cdt.core.dom.ast.IASTTranslationUnit, org.eclipse.cdt.core.IPositionConverter, org.eclipse.core.runtime.IProgressMonitor)
|
||||||
*/
|
*/
|
||||||
public void reconciled(IASTTranslationUnit ast, IPositionConverter positionTracker, IProgressMonitor progressMonitor) {
|
public void reconciled(IASTTranslationUnit ast, IPositionConverter positionTracker, IProgressMonitor progressMonitor) {
|
||||||
if (fInput == null || ast == null || fReconciling) {
|
if (fInput == null || fReconciling) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (fPreprocessorBranchFoldingEnabled && ast == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fReconciling= true;
|
fReconciling= true;
|
||||||
try {
|
try {
|
||||||
FoldingStructureComputationContext ctx= createContext(fInitialASTReconcile);
|
FoldingStructureComputationContext ctx= createContext(fInitialReconcilePending);
|
||||||
fInitialASTReconcile= false;
|
fInitialReconcilePending= false;
|
||||||
if (fPreprocessorBranchFoldingEnabled) {
|
if (fPreprocessorBranchFoldingEnabled) {
|
||||||
ctx.fAST= ast;
|
ctx.fAST= ast;
|
||||||
ctx.fASTPositionConverter= positionTracker;
|
ctx.fASTPositionConverter= positionTracker;
|
||||||
|
@ -350,44 +351,6 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private class ElementChangedListener implements IElementChangedListener {
|
|
||||||
|
|
||||||
/*
|
|
||||||
* @see org.eclipse.cdt.core.IElementChangedListener#elementChanged(org.eclipse.cdt.core.ElementChangedEvent)
|
|
||||||
*/
|
|
||||||
public void elementChanged(ElementChangedEvent e) {
|
|
||||||
ICElementDelta delta= findElement(fInput, e.getDelta());
|
|
||||||
if (delta != null)
|
|
||||||
update(createContext(false));
|
|
||||||
}
|
|
||||||
|
|
||||||
private ICElementDelta findElement(ICElement target, ICElementDelta delta) {
|
|
||||||
|
|
||||||
if (delta == null || target == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
ICElement element= delta.getElement();
|
|
||||||
|
|
||||||
if (element.getElementType() > ICElement.C_UNIT)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
if (target.equals(element))
|
|
||||||
return delta;
|
|
||||||
|
|
||||||
ICElementDelta[] children= delta.getAffectedChildren();
|
|
||||||
if (children == null || children.length == 0)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
for (int i= 0; i < children.length; i++) {
|
|
||||||
ICElementDelta d= findElement(target, children[i]);
|
|
||||||
if (d != null)
|
|
||||||
return d;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Projection position that will return two foldable regions: one folding away
|
* Projection position that will return two foldable regions: one folding away
|
||||||
* the region from after the '/*' to the beginning of the content, the other
|
* the region from after the '/*' to the beginning of the content, the other
|
||||||
|
@ -705,7 +668,7 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
||||||
private boolean fCommentFoldingEnabled= true;
|
private boolean fCommentFoldingEnabled= true;
|
||||||
|
|
||||||
private ICReconcilingListener fReconilingListener;
|
private ICReconcilingListener fReconilingListener;
|
||||||
boolean fInitialASTReconcile= true;
|
boolean fInitialReconcilePending= true;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -781,15 +744,10 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
||||||
handleProjectionDisabled();
|
handleProjectionDisabled();
|
||||||
|
|
||||||
if (fEditor instanceof CEditor) {
|
if (fEditor instanceof CEditor) {
|
||||||
fInitialASTReconcile= true;
|
fInitialReconcilePending= true;
|
||||||
initialize();
|
initialize();
|
||||||
if (fPreprocessorBranchFoldingEnabled || fCommentFoldingEnabled) {
|
|
||||||
fReconilingListener= new PreprocessorBranchesReconciler();
|
fReconilingListener= new PreprocessorBranchesReconciler();
|
||||||
((CEditor)fEditor).addReconcileListener(fReconilingListener);
|
((CEditor)fEditor).addReconcileListener(fReconilingListener);
|
||||||
} else {
|
|
||||||
fElementListener= new ElementChangedListener();
|
|
||||||
CoreModel.getDefault().addElementChangedListener(fElementListener);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1087,11 +1045,6 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
IParent parent= (IParent) fInput;
|
|
||||||
try {
|
|
||||||
computeFoldingStructure(parent.getChildren(), ctx);
|
|
||||||
} catch (CModelException x) {
|
|
||||||
}
|
|
||||||
if (fPreprocessorBranchFoldingEnabled) {
|
if (fPreprocessorBranchFoldingEnabled) {
|
||||||
IASTTranslationUnit ast= ctx.getAST();
|
IASTTranslationUnit ast= ctx.getAST();
|
||||||
if (ast == null) {
|
if (ast == null) {
|
||||||
|
@ -1101,19 +1054,26 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
||||||
if (ast != null) {
|
if (ast != null) {
|
||||||
ctx.fAST= ast;
|
ctx.fAST= ast;
|
||||||
ctx.fASTPositionConverter= null;
|
ctx.fASTPositionConverter= null;
|
||||||
fInitialASTReconcile= false;
|
fInitialReconcilePending= false;
|
||||||
computeFoldingStructure(ast, ctx);
|
computeFoldingStructure(ast, ctx);
|
||||||
}
|
}
|
||||||
return Status.OK_STATUS;
|
return Status.OK_STATUS;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!status.isOK()) {
|
if (status.matches(IStatus.ERROR)) {
|
||||||
CUIPlugin.getDefault().log(status);
|
CUIPlugin.getDefault().log(status);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
computeFoldingStructure(ast, ctx);
|
computeFoldingStructure(ast, ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!fInitialReconcilePending) {
|
||||||
|
IParent parent= (IParent) fInput;
|
||||||
|
try {
|
||||||
|
computeFoldingStructure(parent.getChildren(), ctx);
|
||||||
|
} catch (CModelException x) {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue