1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-04 14:13:24 +02:00

Fixes for API problems.

This commit is contained in:
Markus Schorn 2009-10-23 11:32:02 +00:00
parent 037ae1d1b3
commit 432edada85
13 changed files with 119 additions and 282 deletions

View file

@ -171,21 +171,6 @@ public interface ITranslationUnit extends ICElement, IParent, IOpenable, ISource
*/ */
INamespace createNamespace (String namespace, ICElement sibling, IProgressMonitor monitor) throws CModelException; INamespace createNamespace (String namespace, ICElement sibling, IProgressMonitor monitor) throws CModelException;
/**
* Finds the shared working copy for this element, given a <code>IBuffer</code> factory.
* If no working copy has been created for this element associated with this
* buffer factory, returns <code>null</code>.
* <p>
* Users of this method must not destroy the resulting working copy.
*
* @param bufferFactory the given <code>IBuffer</code> factory
* @return the found shared working copy for this element, <code>null</code> if none
* @see IBufferFactory
* @since 2.0
* @noreference This method is not intended to be referenced by clients.
*/
IWorkingCopy findSharedWorkingCopy(IBufferFactory bufferFactory);
/** /**
* Returns the shared working copy for this element, using the default <code>IBuffer</code> factory, or * Returns the shared working copy for this element, using the default <code>IBuffer</code> factory, or
* <code>null</code>, if no working copy has been created for this element. * <code>null</code>, if no working copy has been created for this element.
@ -271,100 +256,7 @@ public interface ITranslationUnit extends ICElement, IParent, IOpenable, ISource
* exception occurs while accessing its corresponding resource * exception occurs while accessing its corresponding resource
*/ */
IInclude[] getIncludes() throws CModelException; IInclude[] getIncludes() throws CModelException;
/**
* Returns a shared working copy on this element using the given factory to create
* the buffer, or this element if this element is already a working copy.
* This API can only answer an already existing working copy if it is based on the same
* original translation unit AND was using the same buffer factory (i.e. as
* defined by <code>Object#equals</code>).
* <p>
* The life time of a shared working copy is as follows:
* <ul>
* <li>The first call to <code>getSharedWorkingCopy(...)</code> creates a new working copy for this
* element</li>
* <li>Subsequent calls increment an internal counter.</li>
* <li>A call to <code>destroy()</code> decrements the internal counter.</li>
* <li>When this counter is 0, the working copy is destroyed.
* </ul>
* So users of this method must destroy exactly once the working copy.
* <p>
* Note that the buffer factory will be used for the life time of this working copy, i.e. if the
* working copy is closed then reopened, this factory will be used.
* The buffer will be automatically initialized with the original's compilation unit content
* upon creation.
* <p>
* When the shared working copy instance is created, an ADDED ICElementDelta is reported on this
* working copy.
*
* @param monitor a progress monitor used to report progress while opening this compilation unit
* or <code>null</code> if no progress should be reported
* @param factory the factory that creates a buffer that is used to get the content of the working copy
* or <code>null</code> if the internal factory should be used
* @param problemRequestor a requestor which will get notified of problems detected during
* reconciling as they are discovered. The requestor can be set to <code>null</code> indicating
* that the client is not interested in problems.
* @exception CModelException if the contents of this element can not be
* determined. Reasons include:
* <ul>
* <li> This C element does not exist (ELEMENT_DOES_NOT_EXIST)</li>
* </ul>
* @return a shared working copy on this element using the given factory to create
* the buffer, or this element if this element is already a working copy
* @see IBufferFactory
* @see IProblemRequestor
* @since 2.0
* @noreference This method is not intended to be referenced by clients.
*/
IWorkingCopy getSharedWorkingCopy(IProgressMonitor monitor, IBufferFactory factory)
throws CModelException;
/**
* Returns a shared working copy on this element using the given factory to create
* the buffer, or this element if this element is already a working copy.
* This API can only answer an already existing working copy if it is based on the same
* original translation unit AND was using the same buffer factory (i.e. as
* defined by <code>Object#equals</code>).
* <p>
* The life time of a shared working copy is as follows:
* <ul>
* <li>The first call to <code>getSharedWorkingCopy(...)</code> creates a new working copy for this
* element</li>
* <li>Subsequent calls increment an internal counter.</li>
* <li>A call to <code>destroy()</code> decrements the internal counter.</li>
* <li>When this counter is 0, the working copy is destroyed.
* </ul>
* So users of this method must destroy exactly once the working copy.
* <p>
* Note that the buffer factory will be used for the life time of this working copy, i.e. if the
* working copy is closed then reopened, this factory will be used.
* The buffer will be automatically initialized with the original's compilation unit content
* upon creation.
* <p>
* When the shared working copy instance is created, an ADDED ICElementDelta is reported on this
* working copy.
*
* @param monitor a progress monitor used to report progress while opening this compilation unit
* or <code>null</code> if no progress should be reported
* @param factory the factory that creates a buffer that is used to get the content of the working copy
* or <code>null</code> if the internal factory should be used
* @param problemRequestor a requestor which will get notified of problems detected during
* reconciling as they are discovered. The requestor can be set to <code>null</code> indicating
* that the client is not interested in problems.
* @exception CModelException if the contents of this element can not be
* determined. Reasons include:
* <ul>
* <li> This C element does not exist (ELEMENT_DOES_NOT_EXIST)</li>
* </ul>
* @return a shared working copy on this element using the given factory to create
* the buffer, or this element if this element is already a working copy
* @see IBufferFactory
* @see IProblemRequestor
* @since 2.0
* @noreference This method is not intended to be referenced by clients.
*/
IWorkingCopy getSharedWorkingCopy(IProgressMonitor monitor, IBufferFactory factory, IProblemRequestor requestor) throws CModelException;
/** /**
* Returns a shared working copy on this element using the given factory to create the buffer, or this * Returns a shared working copy on this element using the given factory to create the buffer, or this
* element if this element is already a working copy. This API can only answer an already existing working * element if this element is already a working copy. This API can only answer an already existing working
@ -485,12 +377,6 @@ public interface ITranslationUnit extends ICElement, IParent, IOpenable, ISource
*/ */
IWorkingCopy getWorkingCopy(IProgressMonitor monitor) throws CModelException; IWorkingCopy getWorkingCopy(IProgressMonitor monitor) throws CModelException;
/**
* Returns a new working copy for the Translation Unit.
* @noreference This method is not intended to be referenced by clients.
*/
IWorkingCopy getWorkingCopy(IProgressMonitor monitor, IBufferFactory factory) throws CModelException;
/** /**
* Return the contentType id for this file. * Return the contentType id for this file.
* @return String - contentType id * @return String - contentType id

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2000, 2008 QNX Software Systems and others. * Copyright (c) 2000, 2009 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
@ -50,6 +50,7 @@ import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IElementChangedListener; import org.eclipse.cdt.core.model.IElementChangedListener;
import org.eclipse.cdt.core.model.IIncludeReference; import org.eclipse.cdt.core.model.IIncludeReference;
import org.eclipse.cdt.core.model.IParent; import org.eclipse.cdt.core.model.IParent;
import org.eclipse.cdt.core.model.IProblemRequestor;
import org.eclipse.cdt.core.model.ISourceRoot; import org.eclipse.cdt.core.model.ISourceRoot;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy; import org.eclipse.cdt.core.model.IWorkingCopy;
@ -72,6 +73,7 @@ import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.ISafeRunnable; import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.SafeRunner; import org.eclipse.core.runtime.SafeRunner;
@ -123,7 +125,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
/** /**
* A map from ITranslationUnit to IWorkingCopy of the shared working copies. * A map from ITranslationUnit to IWorkingCopy of the shared working copies.
*/ */
public Map<IBufferFactory, Map<ITranslationUnit, WorkingCopy>> sharedWorkingCopies = new HashMap<IBufferFactory, Map<ITranslationUnit, WorkingCopy>>(); private Map<IBufferFactory, Map<ITranslationUnit, WorkingCopy>> sharedWorkingCopies = new HashMap<IBufferFactory, Map<ITranslationUnit, WorkingCopy>>();
/** /**
* Set of elements which are out of sync with their buffers. * Set of elements which are out of sync with their buffers.
*/ */
@ -1277,4 +1279,61 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
CCoreInternals.getPDOMManager().preCloseProject(create(project)); CCoreInternals.getPDOMManager().preCloseProject(create(project));
} }
public IWorkingCopy[] getSharedWorkingCopies(IBufferFactory factory) {
// if factory is null, default factory must be used
if (factory == null)
factory = BufferManager.getDefaultBufferManager().getDefaultBufferFactory();
Map<ITranslationUnit, WorkingCopy> perFactoryWorkingCopies = sharedWorkingCopies.get(factory);
if (perFactoryWorkingCopies == null)
return NoWorkingCopy;
Collection<WorkingCopy> copies = perFactoryWorkingCopies.values();
return copies.toArray(new IWorkingCopy[copies.size()]);
}
public IWorkingCopy findSharedWorkingCopy(IBufferFactory factory, ITranslationUnit tu) {
// if factory is null, default factory must be used
if (factory == null)
factory = BufferManager.getDefaultBufferManager();
Map<ITranslationUnit, WorkingCopy> perFactoryWorkingCopies = sharedWorkingCopies.get(factory);
if (perFactoryWorkingCopies == null)
return null;
return perFactoryWorkingCopies.get(tu);
}
public IWorkingCopy getSharedWorkingCopy(IBufferFactory factory, ITranslationUnit tu, IProblemRequestor requestor,
IProgressMonitor monitor) throws CModelException {
// if factory is null, default factory must be used
if (factory == null)
factory = BufferManager.getDefaultBufferManager();
Map<ITranslationUnit, WorkingCopy> perFactoryWorkingCopies = sharedWorkingCopies.get(factory);
if (perFactoryWorkingCopies == null) {
perFactoryWorkingCopies = new HashMap<ITranslationUnit, WorkingCopy>();
sharedWorkingCopies.put(factory, perFactoryWorkingCopies);
}
WorkingCopy workingCopy = perFactoryWorkingCopies.get(this);
if (workingCopy != null) {
workingCopy.useCount++;
return workingCopy;
}
CreateWorkingCopyOperation op = new CreateWorkingCopyOperation(tu, perFactoryWorkingCopies,
factory, requestor);
op.runOperation(monitor);
return (IWorkingCopy) op.getResultElements()[0];
}
public IWorkingCopy removeSharedWorkingCopy(final IBufferFactory bufferFactory, ITranslationUnit originalElement) {
// In order to be shared, working copies have to denote the same compilation unit
// AND use the same buffer factory.
// Assuming there is a little set of buffer factories, then use a 2 level Map cache.
Map<ITranslationUnit, WorkingCopy> perFactoryWorkingCopies = sharedWorkingCopies.get(bufferFactory);
if (perFactoryWorkingCopies != null) {
return perFactoryWorkingCopies.remove(originalElement);
}
return null;
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2000, 2008 IBM Corporation and others. * Copyright (c) 2000, 2009 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
@ -10,11 +10,10 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.model; package org.eclipse.cdt.internal.core.model;
import java.util.Map;
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.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy;
/** /**
* Destroys a working copy (remove it from its cache if it is shared) * Destroys a working copy (remove it from its cache if it is shared)
@ -37,26 +36,18 @@ public class DestroyWorkingCopyOperation extends CModelOperation {
workingCopy.close(); workingCopy.close();
// if original element is not on classpath flush it from the cache // if original element is not on classpath flush it from the cache
ICElement originalElement = workingCopy.getOriginalElement(); ITranslationUnit originalElement = workingCopy.getOriginalElement();
if (!workingCopy.getParent().exists()) { if (!workingCopy.getParent().exists()) {
((TranslationUnit)originalElement).close(); originalElement.close();
} }
// remove working copy from the cache if it is shared // remove working copy from the cache if it is shared
CModelManager manager = CModelManager.getDefault(); IWorkingCopy wc = CModelManager.getDefault().removeSharedWorkingCopy(workingCopy.bufferFactory, originalElement);
if (wc != null) {
// In order to be shared, working copies have to denote the same compilation unit //System.out.println("Destroying shared working copy " + workingCopy.toStringWithAncestors());//$NON-NLS-1$
// AND use the same buffer factory. //CModelManager.getDefault().fire(delta, ElementChangedEvent.POST_RECONCILE);
// Assuming there is a little set of buffer factories, then use a 2 level Map cache.
Map<IBufferFactory, Map<ITranslationUnit, WorkingCopy>> sharedWorkingCopies = manager.sharedWorkingCopies;
Map<ITranslationUnit, WorkingCopy> perFactoryWorkingCopies = sharedWorkingCopies.get(workingCopy.bufferFactory);
if (perFactoryWorkingCopies != null) {
if (perFactoryWorkingCopies.remove(originalElement) != null) {
//System.out.println("Destroying shared working copy " + workingCopy.toStringWithAncestors());//$NON-NLS-1$
//CModelManager.getDefault().fire(delta, ElementChangedEvent.POST_RECONCILE);
}
} }
// report C deltas // report C deltas
CElementDelta delta = new CElementDelta(this.getCModel()); CElementDelta delta = new CElementDelta(this.getCModel());

View file

@ -20,7 +20,6 @@ import java.io.InputStream;
import java.net.URI; import java.net.URI;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -402,22 +401,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
} }
public IWorkingCopy findSharedWorkingCopy() { public IWorkingCopy findSharedWorkingCopy() {
return findSharedWorkingCopy(null); return CModelManager.getDefault().findSharedWorkingCopy(null, this);
}
public IWorkingCopy findSharedWorkingCopy(IBufferFactory factory) {
// if factory is null, default factory must be used
if (factory == null) factory = BufferManager.getDefaultBufferManager();
// In order to be shared, working copies have to denote the same translation unit
// AND use the same buffer factory.
// Assuming there is a little set of buffer factories, then use a 2 level Map cache.
Map<IBufferFactory, Map<ITranslationUnit, WorkingCopy>> sharedWorkingCopies = CModelManager.getDefault().sharedWorkingCopies;
Map<ITranslationUnit, WorkingCopy> perFactoryWorkingCopies = sharedWorkingCopies.get(factory);
if (perFactoryWorkingCopies == null) return null;
return perFactoryWorkingCopies.get(this);
} }
@Override @Override
@ -457,40 +441,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
public IWorkingCopy getSharedWorkingCopy(IProgressMonitor monitor, IProblemRequestor requestor) public IWorkingCopy getSharedWorkingCopy(IProgressMonitor monitor, IProblemRequestor requestor)
throws CModelException { throws CModelException {
return getSharedWorkingCopy(monitor, null, requestor); return CModelManager.getDefault().getSharedWorkingCopy(null, this, requestor, monitor);
}
public IWorkingCopy getSharedWorkingCopy(IProgressMonitor monitor,IBufferFactory factory)
throws CModelException {
return getSharedWorkingCopy(monitor, factory, null);
}
public IWorkingCopy getSharedWorkingCopy(IProgressMonitor monitor,IBufferFactory factory, IProblemRequestor requestor)
throws CModelException {
// if factory is null, default factory must be used
if (factory == null) factory = BufferManager.getDefaultBufferManager();
CModelManager manager = CModelManager.getDefault();
// In order to be shared, working copies have to denote the same translation unit
// AND use the same buffer factory.
// Assuming there is a little set of buffer factories, then use a 2 level Map cache.
Map<IBufferFactory, Map<ITranslationUnit, WorkingCopy>> sharedWorkingCopies = manager.sharedWorkingCopies;
Map<ITranslationUnit, WorkingCopy> perFactoryWorkingCopies = sharedWorkingCopies.get(factory);
if (perFactoryWorkingCopies == null) {
perFactoryWorkingCopies = new HashMap<ITranslationUnit, WorkingCopy>();
sharedWorkingCopies.put(factory, perFactoryWorkingCopies);
}
WorkingCopy workingCopy = perFactoryWorkingCopies.get(this);
if (workingCopy != null) {
workingCopy.useCount++;
return workingCopy;
}
CreateWorkingCopyOperation op = new CreateWorkingCopyOperation(this, perFactoryWorkingCopies, factory, requestor);
op.runOperation(monitor);
return (IWorkingCopy) op.getResultElements()[0];
} }
public IWorkingCopy getWorkingCopy() throws CModelException { public IWorkingCopy getWorkingCopy() throws CModelException {

View file

@ -1,18 +1,17 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2002, 2008 IBM Corporation and others. * Copyright (c) 2002, 2009 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
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Rational Software - Initial API and implementation * Rational Software - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* Anton Leherbauer (Wind River Systems) * Anton Leherbauer (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.model; package org.eclipse.cdt.internal.core.model;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
@ -232,12 +231,11 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
} }
/** /**
* @see org.eclipse.cdt.core.model.ITranslationUnit#getSharedWorkingCopy(IProgressMonitor, IBufferFactory) * @see org.eclipse.cdt.core.model.ITranslationUnit#getSharedWorkingCopy(IProgressMonitor, IProblemRequestor)
*/ */
@Override @Override
public IWorkingCopy getSharedWorkingCopy(IProgressMonitor monitor,IBufferFactory factory) public IWorkingCopy getSharedWorkingCopy(IProgressMonitor monitor, IProblemRequestor requestor) {
throws CModelException{ return this;
return this;
} }
/** /**
* @see org.eclipse.cdt.core.model.ITranslationUnit#getWorkingCopy() * @see org.eclipse.cdt.core.model.ITranslationUnit#getWorkingCopy()
@ -251,7 +249,7 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
* @see IWorkingCopy * @see IWorkingCopy
*/ */
@Override @Override
public IWorkingCopy getWorkingCopy(IProgressMonitor monitor, IBufferFactory factory){ public IWorkingCopy getWorkingCopy(IProgressMonitor monitor){
return this; return this;
} }

View file

@ -16,10 +16,8 @@ package org.eclipse.cdt.core;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map;
import java.util.MissingResourceException; import java.util.MissingResourceException;
import java.util.ResourceBundle; import java.util.ResourceBundle;
@ -50,11 +48,8 @@ import org.eclipse.cdt.internal.core.PositionTrackerManager;
import org.eclipse.cdt.internal.core.cdtvariables.CdtVariableManager; import org.eclipse.cdt.internal.core.cdtvariables.CdtVariableManager;
import org.eclipse.cdt.internal.core.cdtvariables.UserVarSupplier; import org.eclipse.cdt.internal.core.cdtvariables.UserVarSupplier;
import org.eclipse.cdt.internal.core.envvar.EnvironmentVariableManager; import org.eclipse.cdt.internal.core.envvar.EnvironmentVariableManager;
import org.eclipse.cdt.internal.core.model.BufferManager;
import org.eclipse.cdt.internal.core.model.CModelManager; import org.eclipse.cdt.internal.core.model.CModelManager;
import org.eclipse.cdt.internal.core.model.IBufferFactory;
import org.eclipse.cdt.internal.core.model.Util; import org.eclipse.cdt.internal.core.model.Util;
import org.eclipse.cdt.internal.core.model.WorkingCopy;
import org.eclipse.cdt.internal.core.pdom.PDOMManager; import org.eclipse.cdt.internal.core.pdom.PDOMManager;
import org.eclipse.cdt.internal.core.resources.ResourceLookup; import org.eclipse.cdt.internal.core.resources.ResourceLookup;
import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager; import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager;
@ -225,7 +220,7 @@ public class CCorePlugin extends Plugin {
* @since 5.1 * @since 5.1
*/ */
public static IWorkingCopy[] getSharedWorkingCopies() { public static IWorkingCopy[] getSharedWorkingCopies() {
return getSharedWorkingCopies(null); return CModelManager.getDefault().getSharedWorkingCopies(null);
} }
public static String getResourceString(String key) { public static String getResourceString(String key) {
@ -1174,32 +1169,6 @@ public class CCorePlugin extends Plugin {
super(); super();
fgCPlugin = this; fgCPlugin = this;
} }
/**
* Answers the shared working copies currently registered for this buffer factory.
* Working copies can be shared by several clients using the same buffer factory,see
* <code>IWorkingCopy.getSharedWorkingCopy</code>.
*
* @param factory the given buffer factory
* @return the list of shared working copies for a given buffer factory
* @see IWorkingCopy
* @noreference This method is not intended to be referenced by clients.
*/
public static IWorkingCopy[] getSharedWorkingCopies(IBufferFactory factory) {
// if factory is null, default factory must be used
if (factory == null)
factory = BufferManager.getDefaultBufferManager().getDefaultBufferFactory();
Map<IBufferFactory, Map<ITranslationUnit, WorkingCopy>> sharedWorkingCopies = CModelManager
.getDefault().sharedWorkingCopies;
Map<ITranslationUnit, WorkingCopy> perFactoryWorkingCopies = sharedWorkingCopies.get(factory);
if (perFactoryWorkingCopies == null)
return CModelManager.NoWorkingCopy;
Collection<WorkingCopy> copies = perFactoryWorkingCopies.values();
IWorkingCopy[] result = new IWorkingCopy[copies.size()];
copies.toArray(result);
return result;
}
/** /**
* @noreference This method is not intended to be referenced by clients. * @noreference This method is not intended to be referenced by clients.

View file

@ -49,6 +49,8 @@ import org.eclipse.cdt.ui.CElementGrouping;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.IncludesGrouping; import org.eclipse.cdt.ui.IncludesGrouping;
import org.eclipse.cdt.ui.NamespacesGrouping; import org.eclipse.cdt.ui.NamespacesGrouping;
import org.eclipse.cdt.internal.core.model.CModelManager;
/** /**
* A base content provider for C elements. It provides access to the * A base content provider for C elements. It provides access to the
@ -208,7 +210,7 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
// if it is not already a working copy // if it is not already a working copy
if (!(element instanceof IWorkingCopy)){ if (!(element instanceof IWorkingCopy)){
// if it has a valid working copy // if it has a valid working copy
IWorkingCopy copy = tu.findSharedWorkingCopy(CUIPlugin.getDefault().getBufferFactory()); IWorkingCopy copy = CModelManager.getDefault().findSharedWorkingCopy(CUIPlugin.getDefault().getBufferFactory(), tu);
if (copy != null) { if (copy != null) {
tu = copy; tu = copy;
} }
@ -389,8 +391,7 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
List<ICElement> list= new ArrayList<ICElement>(); List<ICElement> list= new ArrayList<ICElement>();
ICElement[] children = cproject.getChildren(); ICElement[] children = cproject.getChildren();
for (int i= 0; i < children.length; i++) { for (ICElement child : children) {
ICElement child = children[i];
if (child instanceof ISourceRoot && child.getResource().getType() == IResource.PROJECT) { if (child instanceof ISourceRoot && child.getResource().getType() == IResource.PROJECT) {
// Was a source root at the project, get the children of this element // Was a source root at the project, get the children of this element
ICElement[] c2 = ((ISourceRoot)child).getChildren(); ICElement[] c2 = ((ISourceRoot)child).getChildren();
@ -565,8 +566,8 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
roots = new ISourceRoot[0]; roots = new ISourceRoot[0];
} }
List<Object> nonCResources = new ArrayList<Object>(objects.length); List<Object> nonCResources = new ArrayList<Object>(objects.length);
for (int i= 0; i < objects.length; i++) { for (Object object : objects) {
Object o= objects[i]; Object o= object;
// A folder can also be a source root in the following case // A folder can also be a source root in the following case
// Project // Project
// + src <- source folder // + src <- source folder
@ -577,8 +578,8 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
if (o instanceof IFolder) { if (o instanceof IFolder) {
IFolder folder = (IFolder)o; IFolder folder = (IFolder)o;
boolean found = false; boolean found = false;
for (int j = 0; j < roots.length; j++) { for (ISourceRoot root : roots) {
if (roots[j].getPath().equals(folder.getFullPath())) { if (root.getPath().equals(folder.getFullPath())) {
found = true; found = true;
break; break;
} }
@ -589,19 +590,19 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
} }
} else if (o instanceof IFile){ } else if (o instanceof IFile){
boolean found = false; boolean found = false;
for (int j = 0; j < binaries.length; j++) { for (ICElement binarie : binaries) {
IResource res = binaries[j].getResource(); IResource res = binarie.getResource();
if (o.equals(res)) { if (o.equals(res)) {
o = binaries[j]; o = binarie;
found = true; found = true;
break; break;
} }
} }
if (!found) { if (!found) {
for (int j = 0; j < archives.length; j++) { for (ICElement archive : archives) {
IResource res = archives[j].getResource(); IResource res = archive.getResource();
if (o.equals(res)) { if (o.equals(res)) {
o = archives[j]; o = archive;
break; break;
} }
} }
@ -641,9 +642,9 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
protected IBinary[] getBinaries(IBinaryContainer container) throws CModelException { protected IBinary[] getBinaries(IBinaryContainer container) throws CModelException {
ICElement[] celements = container.getChildren(); ICElement[] celements = container.getChildren();
ArrayList<IBinary> list = new ArrayList<IBinary>(celements.length); ArrayList<IBinary> list = new ArrayList<IBinary>(celements.length);
for (int i = 0; i < celements.length; i++) { for (ICElement celement : celements) {
if (celements[i] instanceof IBinary) { if (celement instanceof IBinary) {
IBinary bin = (IBinary)celements[i]; IBinary bin = (IBinary)celement;
list.add(bin); list.add(bin);
} }
} }
@ -660,9 +661,9 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
protected IArchive[] getArchives(IArchiveContainer container) throws CModelException { protected IArchive[] getArchives(IArchiveContainer container) throws CModelException {
ICElement[] celements = container.getChildren(); ICElement[] celements = container.getChildren();
ArrayList<IArchive> list = new ArrayList<IArchive>(celements.length); ArrayList<IArchive> list = new ArrayList<IArchive>(celements.length);
for (int i = 0; i < celements.length; i++) { for (ICElement celement : celements) {
if (celements[i] instanceof IArchive) { if (celement instanceof IArchive) {
IArchive ar = (IArchive)celements[i]; IArchive ar = (IArchive)celement;
list.add(ar); list.add(ar);
} }
} }

View file

@ -81,6 +81,7 @@ import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants; import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.text.ICPartitions; import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.cdt.internal.core.model.CModelManager;
import org.eclipse.cdt.internal.core.model.IBufferFactory; import org.eclipse.cdt.internal.core.model.IBufferFactory;
import org.eclipse.cdt.internal.core.model.TranslationUnit; import org.eclipse.cdt.internal.core.model.TranslationUnit;
@ -861,7 +862,7 @@ public class CDocumentProvider extends TextFileDocumentProvider {
IProblemRequestor requestor= tuInfo.fModel instanceof IProblemRequestor ? (IProblemRequestor) tuInfo.fModel : null; IProblemRequestor requestor= tuInfo.fModel instanceof IProblemRequestor ? (IProblemRequestor) tuInfo.fModel : null;
IBufferFactory factory = CUIPlugin.getDefault().getBufferFactory(); IBufferFactory factory = CUIPlugin.getDefault().getBufferFactory();
tuInfo.fCopy = original.getSharedWorkingCopy(getProgressMonitor(), factory, requestor); tuInfo.fCopy = CModelManager.getDefault().getSharedWorkingCopy(factory, original, requestor, getProgressMonitor());
if (tuInfo.fModel == null) { if (tuInfo.fModel == null) {
IPath location = original.getLocation(); IPath location = original.getLocation();

View file

@ -27,10 +27,11 @@ import org.eclipse.text.edits.UndoEdit;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.IBuffer; import org.eclipse.cdt.core.model.IBuffer;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy; import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.core.model.TranslationUnit;
/** /**
* UndoCTextFileChange that uses a working copy in order to generate CModel events. * UndoCTextFileChange that uses a working copy in order to generate CModel events.
* @author janees * @author janees
@ -61,11 +62,11 @@ public class UndoCTextFileChange
} }
final IFile file = (IFile) obj; final IFile file = (IFile) obj;
ICElement element = CoreModel.getDefault().create(file); ICElement element = CoreModel.getDefault().create(file);
if (!(element instanceof ITranslationUnit)) { if (!(element instanceof TranslationUnit)) {
return super.perform(pm); return super.perform(pm);
} }
final ITranslationUnit tu = (ITranslationUnit) element; final TranslationUnit tu = (TranslationUnit) element;
IWorkingCopy wc= tu.getWorkingCopy(pm, DocumentAdapter.FACTORY); IWorkingCopy wc= tu.getWorkingCopy(pm, DocumentAdapter.FACTORY);
final IBuffer buffer= wc.getBuffer(); final IBuffer buffer= wc.getBuffer();
assert buffer instanceof DocumentAdapter; assert buffer instanceof DocumentAdapter;

View file

@ -35,7 +35,6 @@ import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
import org.eclipse.ltk.core.refactoring.RefactoringStatus; import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.text.edits.TextEditGroup; import org.eclipse.text.edits.TextEditGroup;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTComment; import org.eclipse.cdt.core.dom.ast.IASTComment;
@ -214,11 +213,6 @@ public class ExtractFunctionRefactoring extends CRefactoring {
} }
} }
} }
if(unit != null) {
IIndex index = CCorePlugin.getIndexManager().getIndex(project);
unit.setIndex(index);
}
sm.done(); sm.done();
} }
finally { finally {

View file

@ -20,7 +20,6 @@ import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.ibm.icu.text.MessageFormat;
import org.eclipse.compare.rangedifferencer.IRangeComparator; import org.eclipse.compare.rangedifferencer.IRangeComparator;
import org.eclipse.compare.rangedifferencer.RangeDifference; import org.eclipse.compare.rangedifferencer.RangeDifference;
@ -73,6 +72,8 @@ import org.eclipse.ui.ide.ResourceUtil;
import org.eclipse.ui.part.FileEditorInput; import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.texteditor.ITextEditor; import org.eclipse.ui.texteditor.ITextEditor;
import com.ibm.icu.text.MessageFormat;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
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;
@ -88,6 +89,7 @@ import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.resources.FileStorage; import org.eclipse.cdt.core.resources.FileStorage;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.core.model.CModelManager;
import org.eclipse.cdt.internal.core.resources.ResourceLookup; import org.eclipse.cdt.internal.core.resources.ResourceLookup;
import org.eclipse.cdt.internal.ui.ICStatusConstants; import org.eclipse.cdt.internal.ui.ICStatusConstants;
@ -540,7 +542,7 @@ public class EditorUtility {
if (cu.isWorkingCopy()) if (cu.isWorkingCopy())
return cu; return cu;
return cu.findSharedWorkingCopy(CUIPlugin.getDefault().getBufferFactory()); return CModelManager.getDefault().findSharedWorkingCopy(CUIPlugin.getDefault().getBufferFactory(), cu);
} }
/** /**
@ -828,8 +830,7 @@ public class EditorUtility {
List<IRegion> regions= new ArrayList<IRegion>(); List<IRegion> regions= new ArrayList<IRegion>();
final int numberOfLines= currentDocument.getNumberOfLines(); final int numberOfLines= currentDocument.getNumberOfLines();
for (int i= 0; i < differences.length; i++) { for (RangeDifference curr : differences) {
RangeDifference curr= differences[i];
if (curr.kind() == RangeDifference.CHANGE) { if (curr.kind() == RangeDifference.CHANGE) {
int startLine= Math.min(curr.rightStart(), numberOfLines - 1); int startLine= Math.min(curr.rightStart(), numberOfLines - 1);
int endLine= curr.rightEnd() - 1; int endLine= curr.rightEnd() - 1;

View file

@ -73,6 +73,7 @@ import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.model.IWorkingCopyProvider; import org.eclipse.cdt.core.model.IWorkingCopyProvider;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTRewriteAnalyzer; import org.eclipse.cdt.internal.core.dom.rewrite.ASTRewriteAnalyzer;
import org.eclipse.cdt.internal.core.model.CModelManager;
import org.eclipse.cdt.internal.core.model.IBufferFactory; import org.eclipse.cdt.internal.core.model.IBufferFactory;
import org.eclipse.cdt.internal.corext.template.c.CContextType; import org.eclipse.cdt.internal.corext.template.c.CContextType;
import org.eclipse.cdt.internal.corext.template.c.CodeTemplateContextType; import org.eclipse.cdt.internal.corext.template.c.CodeTemplateContextType;
@ -89,7 +90,6 @@ import org.eclipse.cdt.internal.ui.editor.ASTProvider;
import org.eclipse.cdt.internal.ui.editor.CDocumentProvider; import org.eclipse.cdt.internal.ui.editor.CDocumentProvider;
import org.eclipse.cdt.internal.ui.editor.CustomBufferFactory; import org.eclipse.cdt.internal.ui.editor.CustomBufferFactory;
import org.eclipse.cdt.internal.ui.editor.WorkingCopyManager; import org.eclipse.cdt.internal.ui.editor.WorkingCopyManager;
import org.eclipse.cdt.internal.ui.editor.asm.AsmTextTools;
import org.eclipse.cdt.internal.ui.refactoring.CTextFileChangeFactory; import org.eclipse.cdt.internal.ui.refactoring.CTextFileChangeFactory;
import org.eclipse.cdt.internal.ui.text.CTextTools; import org.eclipse.cdt.internal.ui.text.CTextTools;
import org.eclipse.cdt.internal.ui.text.c.hover.CEditorTextHoverDescriptor; import org.eclipse.cdt.internal.ui.text.c.hover.CEditorTextHoverDescriptor;
@ -254,7 +254,7 @@ public class CUIPlugin extends AbstractUIPlugin {
} }
public static IWorkingCopy[] getSharedWorkingCopies() { public static IWorkingCopy[] getSharedWorkingCopies() {
return CCorePlugin.getSharedWorkingCopies(getDefault().getBufferFactory()); return CModelManager.getDefault().getSharedWorkingCopies(getDefault().getBufferFactory());
} }
public static String getResourceString(String key) { public static String getResourceString(String key) {
@ -387,7 +387,6 @@ public class CUIPlugin extends AbstractUIPlugin {
private IBufferFactory fBufferFactory; private IBufferFactory fBufferFactory;
private WorkingCopyManager fWorkingCopyManager; private WorkingCopyManager fWorkingCopyManager;
private CTextTools fTextTools; private CTextTools fTextTools;
private AsmTextTools fAsmTextTools;
private ProblemMarkerManager fProblemMarkerManager; private ProblemMarkerManager fProblemMarkerManager;
private Map<String, BuildConsoleManager> fBuildConsoleManagers; private Map<String, BuildConsoleManager> fBuildConsoleManagers;
private ResourceAdapterFactory fResourceAdapterFactory; private ResourceAdapterFactory fResourceAdapterFactory;
@ -464,18 +463,6 @@ public class CUIPlugin extends AbstractUIPlugin {
return fTextTools; return fTextTools;
} }
/**
* Returns the shared assembly text tools.
* @deprecated Use methods provided by {@link CDTUITools} instead.
* @noreference This method is not intended to be referenced by clients.
*/
@Deprecated
public AsmTextTools getAsmTextTools() {
if (fAsmTextTools == null)
fAsmTextTools = new AsmTextTools();
return fAsmTextTools;
}
/** /**
* Return the default console manager. * Return the default console manager.
* @return IBuildConsoleManager * @return IBuildConsoleManager
@ -563,10 +550,6 @@ public class CUIPlugin extends AbstractUIPlugin {
fTextTools.dispose(); fTextTools.dispose();
fTextTools= null; fTextTools= null;
} }
if (fAsmTextTools != null) {
fAsmTextTools.dispose();
fAsmTextTools= null;
}
if (fImageDescriptorRegistry != null) { if (fImageDescriptorRegistry != null) {
fImageDescriptorRegistry.dispose(); fImageDescriptorRegistry.dispose();
fImageDescriptorRegistry= null; fImageDescriptorRegistry= null;

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2006, 2008 Wind River Systems and others. * Copyright (c) 2006, 2009 Wind River 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
@ -26,6 +26,8 @@ import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy; import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.internal.core.model.TranslationUnit;
import org.eclipse.cdt.internal.ui.refactoring.DocumentAdapter; import org.eclipse.cdt.internal.ui.refactoring.DocumentAdapter;
import org.eclipse.cdt.internal.ui.refactoring.UndoCTextFileChange; import org.eclipse.cdt.internal.ui.refactoring.UndoCTextFileChange;
@ -69,8 +71,8 @@ public class CTextFileChange extends TextFileChange {
protected IDocument acquireDocument(IProgressMonitor pm) throws CoreException { protected IDocument acquireDocument(IProgressMonitor pm) throws CoreException {
IDocument doc= super.acquireDocument(pm); IDocument doc= super.acquireDocument(pm);
if (++fAquireCount == 1) { if (++fAquireCount == 1) {
if (fTranslationUnit != null && fWorkingCopy == null) { if (fTranslationUnit instanceof TranslationUnit && fWorkingCopy == null) {
fWorkingCopy= fTranslationUnit.getWorkingCopy(null, DocumentAdapter.FACTORY); fWorkingCopy= ((TranslationUnit) fTranslationUnit).getWorkingCopy(null, DocumentAdapter.FACTORY);
if (!fTranslationUnit.isOpen()) { if (!fTranslationUnit.isOpen()) {
fTranslationUnit.open(null); fTranslationUnit.open(null);
} }