mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fixes for API problems.
This commit is contained in:
parent
037ae1d1b3
commit
432edada85
13 changed files with 119 additions and 282 deletions
|
@ -171,21 +171,6 @@ public interface ITranslationUnit extends ICElement, IParent, IOpenable, ISource
|
|||
*/
|
||||
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
|
||||
* <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
|
||||
*/
|
||||
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
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* 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 String - contentType id
|
||||
|
|
|
@ -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
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* 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.IIncludeReference;
|
||||
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.ITranslationUnit;
|
||||
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.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.ISafeRunnable;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
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.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
|
@ -1277,4 +1279,61 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -10,11 +10,10 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.model;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
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)
|
||||
|
@ -37,26 +36,18 @@ public class DestroyWorkingCopyOperation extends CModelOperation {
|
|||
workingCopy.close();
|
||||
|
||||
// if original element is not on classpath flush it from the cache
|
||||
ICElement originalElement = workingCopy.getOriginalElement();
|
||||
ITranslationUnit originalElement = workingCopy.getOriginalElement();
|
||||
if (!workingCopy.getParent().exists()) {
|
||||
((TranslationUnit)originalElement).close();
|
||||
originalElement.close();
|
||||
}
|
||||
|
||||
// remove working copy from the cache if it is shared
|
||||
CModelManager manager = CModelManager.getDefault();
|
||||
|
||||
// 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<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);
|
||||
}
|
||||
IWorkingCopy wc = CModelManager.getDefault().removeSharedWorkingCopy(workingCopy.bufferFactory, originalElement);
|
||||
if (wc != null) {
|
||||
//System.out.println("Destroying shared working copy " + workingCopy.toStringWithAncestors());//$NON-NLS-1$
|
||||
//CModelManager.getDefault().fire(delta, ElementChangedEvent.POST_RECONCILE);
|
||||
}
|
||||
|
||||
|
||||
// report C deltas
|
||||
CElementDelta delta = new CElementDelta(this.getCModel());
|
||||
|
|
|
@ -20,7 +20,6 @@ import java.io.InputStream;
|
|||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
@ -402,22 +401,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
|||
}
|
||||
|
||||
public IWorkingCopy findSharedWorkingCopy() {
|
||||
return findSharedWorkingCopy(null);
|
||||
}
|
||||
|
||||
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);
|
||||
return CModelManager.getDefault().findSharedWorkingCopy(null, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -457,40 +441,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
|||
|
||||
public IWorkingCopy getSharedWorkingCopy(IProgressMonitor monitor, IProblemRequestor requestor)
|
||||
throws CModelException {
|
||||
return getSharedWorkingCopy(monitor, null, requestor);
|
||||
}
|
||||
|
||||
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];
|
||||
return CModelManager.getDefault().getSharedWorkingCopy(null, this, requestor, monitor);
|
||||
}
|
||||
|
||||
public IWorkingCopy getWorkingCopy() throws CModelException {
|
||||
|
|
|
@ -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
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Rational Software - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
* Rational Software - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.model;
|
||||
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
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
|
||||
public IWorkingCopy getSharedWorkingCopy(IProgressMonitor monitor,IBufferFactory factory)
|
||||
throws CModelException{
|
||||
return this;
|
||||
public IWorkingCopy getSharedWorkingCopy(IProgressMonitor monitor, IProblemRequestor requestor) {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @see org.eclipse.cdt.core.model.ITranslationUnit#getWorkingCopy()
|
||||
|
@ -251,7 +249,7 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
|
|||
* @see IWorkingCopy
|
||||
*/
|
||||
@Override
|
||||
public IWorkingCopy getWorkingCopy(IProgressMonitor monitor, IBufferFactory factory){
|
||||
public IWorkingCopy getWorkingCopy(IProgressMonitor monitor){
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,10 +16,8 @@ package org.eclipse.cdt.core;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.MissingResourceException;
|
||||
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.UserVarSupplier;
|
||||
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.IBufferFactory;
|
||||
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.resources.ResourceLookup;
|
||||
import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager;
|
||||
|
@ -225,7 +220,7 @@ public class CCorePlugin extends Plugin {
|
|||
* @since 5.1
|
||||
*/
|
||||
public static IWorkingCopy[] getSharedWorkingCopies() {
|
||||
return getSharedWorkingCopies(null);
|
||||
return CModelManager.getDefault().getSharedWorkingCopies(null);
|
||||
}
|
||||
|
||||
public static String getResourceString(String key) {
|
||||
|
@ -1174,32 +1169,6 @@ public class CCorePlugin extends Plugin {
|
|||
super();
|
||||
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.
|
||||
|
|
|
@ -49,6 +49,8 @@ import org.eclipse.cdt.ui.CElementGrouping;
|
|||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.IncludesGrouping;
|
||||
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
|
||||
|
@ -208,7 +210,7 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
|
|||
// if it is not already a working copy
|
||||
if (!(element instanceof IWorkingCopy)){
|
||||
// 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) {
|
||||
tu = copy;
|
||||
}
|
||||
|
@ -389,8 +391,7 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
|
|||
|
||||
List<ICElement> list= new ArrayList<ICElement>();
|
||||
ICElement[] children = cproject.getChildren();
|
||||
for (int i= 0; i < children.length; i++) {
|
||||
ICElement child = children[i];
|
||||
for (ICElement child : children) {
|
||||
if (child instanceof ISourceRoot && child.getResource().getType() == IResource.PROJECT) {
|
||||
// Was a source root at the project, get the children of this element
|
||||
ICElement[] c2 = ((ISourceRoot)child).getChildren();
|
||||
|
@ -565,8 +566,8 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
|
|||
roots = new ISourceRoot[0];
|
||||
}
|
||||
List<Object> nonCResources = new ArrayList<Object>(objects.length);
|
||||
for (int i= 0; i < objects.length; i++) {
|
||||
Object o= objects[i];
|
||||
for (Object object : objects) {
|
||||
Object o= object;
|
||||
// A folder can also be a source root in the following case
|
||||
// Project
|
||||
// + src <- source folder
|
||||
|
@ -577,8 +578,8 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
|
|||
if (o instanceof IFolder) {
|
||||
IFolder folder = (IFolder)o;
|
||||
boolean found = false;
|
||||
for (int j = 0; j < roots.length; j++) {
|
||||
if (roots[j].getPath().equals(folder.getFullPath())) {
|
||||
for (ISourceRoot root : roots) {
|
||||
if (root.getPath().equals(folder.getFullPath())) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
@ -589,19 +590,19 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
|
|||
}
|
||||
} else if (o instanceof IFile){
|
||||
boolean found = false;
|
||||
for (int j = 0; j < binaries.length; j++) {
|
||||
IResource res = binaries[j].getResource();
|
||||
for (ICElement binarie : binaries) {
|
||||
IResource res = binarie.getResource();
|
||||
if (o.equals(res)) {
|
||||
o = binaries[j];
|
||||
o = binarie;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
for (int j = 0; j < archives.length; j++) {
|
||||
IResource res = archives[j].getResource();
|
||||
for (ICElement archive : archives) {
|
||||
IResource res = archive.getResource();
|
||||
if (o.equals(res)) {
|
||||
o = archives[j];
|
||||
o = archive;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -641,9 +642,9 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
|
|||
protected IBinary[] getBinaries(IBinaryContainer container) throws CModelException {
|
||||
ICElement[] celements = container.getChildren();
|
||||
ArrayList<IBinary> list = new ArrayList<IBinary>(celements.length);
|
||||
for (int i = 0; i < celements.length; i++) {
|
||||
if (celements[i] instanceof IBinary) {
|
||||
IBinary bin = (IBinary)celements[i];
|
||||
for (ICElement celement : celements) {
|
||||
if (celement instanceof IBinary) {
|
||||
IBinary bin = (IBinary)celement;
|
||||
list.add(bin);
|
||||
}
|
||||
}
|
||||
|
@ -660,9 +661,9 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
|
|||
protected IArchive[] getArchives(IArchiveContainer container) throws CModelException {
|
||||
ICElement[] celements = container.getChildren();
|
||||
ArrayList<IArchive> list = new ArrayList<IArchive>(celements.length);
|
||||
for (int i = 0; i < celements.length; i++) {
|
||||
if (celements[i] instanceof IArchive) {
|
||||
IArchive ar = (IArchive)celements[i];
|
||||
for (ICElement celement : celements) {
|
||||
if (celement instanceof IArchive) {
|
||||
IArchive ar = (IArchive)celement;
|
||||
list.add(ar);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,6 +81,7 @@ import org.eclipse.cdt.ui.CUIPlugin;
|
|||
import org.eclipse.cdt.ui.PreferenceConstants;
|
||||
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.TranslationUnit;
|
||||
|
||||
|
@ -861,7 +862,7 @@ public class CDocumentProvider extends TextFileDocumentProvider {
|
|||
|
||||
IProblemRequestor requestor= tuInfo.fModel instanceof IProblemRequestor ? (IProblemRequestor) tuInfo.fModel : null;
|
||||
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) {
|
||||
IPath location = original.getLocation();
|
||||
|
|
|
@ -27,10 +27,11 @@ import org.eclipse.text.edits.UndoEdit;
|
|||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.IBuffer;
|
||||
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.ui.CUIPlugin;
|
||||
|
||||
import org.eclipse.cdt.internal.core.model.TranslationUnit;
|
||||
|
||||
/**
|
||||
* UndoCTextFileChange that uses a working copy in order to generate CModel events.
|
||||
* @author janees
|
||||
|
@ -61,11 +62,11 @@ public class UndoCTextFileChange
|
|||
}
|
||||
final IFile file = (IFile) obj;
|
||||
ICElement element = CoreModel.getDefault().create(file);
|
||||
if (!(element instanceof ITranslationUnit)) {
|
||||
if (!(element instanceof TranslationUnit)) {
|
||||
return super.perform(pm);
|
||||
}
|
||||
|
||||
final ITranslationUnit tu = (ITranslationUnit) element;
|
||||
final TranslationUnit tu = (TranslationUnit) element;
|
||||
IWorkingCopy wc= tu.getWorkingCopy(pm, DocumentAdapter.FACTORY);
|
||||
final IBuffer buffer= wc.getBuffer();
|
||||
assert buffer instanceof DocumentAdapter;
|
||||
|
|
|
@ -35,7 +35,6 @@ import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
|
|||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||
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.IASTBinaryExpression;
|
||||
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();
|
||||
}
|
||||
finally {
|
||||
|
|
|
@ -20,7 +20,6 @@ import java.io.IOException;
|
|||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.ibm.icu.text.MessageFormat;
|
||||
|
||||
import org.eclipse.compare.rangedifferencer.IRangeComparator;
|
||||
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.texteditor.ITextEditor;
|
||||
|
||||
import com.ibm.icu.text.MessageFormat;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
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.ui.CUIPlugin;
|
||||
|
||||
import org.eclipse.cdt.internal.core.model.CModelManager;
|
||||
import org.eclipse.cdt.internal.core.resources.ResourceLookup;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.ICStatusConstants;
|
||||
|
@ -540,7 +542,7 @@ public class EditorUtility {
|
|||
if (cu.isWorkingCopy())
|
||||
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>();
|
||||
final int numberOfLines= currentDocument.getNumberOfLines();
|
||||
for (int i= 0; i < differences.length; i++) {
|
||||
RangeDifference curr= differences[i];
|
||||
for (RangeDifference curr : differences) {
|
||||
if (curr.kind() == RangeDifference.CHANGE) {
|
||||
int startLine= Math.min(curr.rightStart(), numberOfLines - 1);
|
||||
int endLine= curr.rightEnd() - 1;
|
||||
|
|
|
@ -73,6 +73,7 @@ import org.eclipse.cdt.core.model.IWorkingCopy;
|
|||
import org.eclipse.cdt.core.model.IWorkingCopyProvider;
|
||||
|
||||
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.corext.template.c.CContextType;
|
||||
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.CustomBufferFactory;
|
||||
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.text.CTextTools;
|
||||
import org.eclipse.cdt.internal.ui.text.c.hover.CEditorTextHoverDescriptor;
|
||||
|
@ -254,7 +254,7 @@ public class CUIPlugin extends AbstractUIPlugin {
|
|||
}
|
||||
|
||||
public static IWorkingCopy[] getSharedWorkingCopies() {
|
||||
return CCorePlugin.getSharedWorkingCopies(getDefault().getBufferFactory());
|
||||
return CModelManager.getDefault().getSharedWorkingCopies(getDefault().getBufferFactory());
|
||||
}
|
||||
|
||||
public static String getResourceString(String key) {
|
||||
|
@ -387,7 +387,6 @@ public class CUIPlugin extends AbstractUIPlugin {
|
|||
private IBufferFactory fBufferFactory;
|
||||
private WorkingCopyManager fWorkingCopyManager;
|
||||
private CTextTools fTextTools;
|
||||
private AsmTextTools fAsmTextTools;
|
||||
private ProblemMarkerManager fProblemMarkerManager;
|
||||
private Map<String, BuildConsoleManager> fBuildConsoleManagers;
|
||||
private ResourceAdapterFactory fResourceAdapterFactory;
|
||||
|
@ -464,18 +463,6 @@ public class CUIPlugin extends AbstractUIPlugin {
|
|||
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 IBuildConsoleManager
|
||||
|
@ -563,10 +550,6 @@ public class CUIPlugin extends AbstractUIPlugin {
|
|||
fTextTools.dispose();
|
||||
fTextTools= null;
|
||||
}
|
||||
if (fAsmTextTools != null) {
|
||||
fAsmTextTools.dispose();
|
||||
fAsmTextTools= null;
|
||||
}
|
||||
if (fImageDescriptorRegistry != null) {
|
||||
fImageDescriptorRegistry.dispose();
|
||||
fImageDescriptorRegistry= null;
|
||||
|
|
|
@ -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
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* 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.IWorkingCopy;
|
||||
|
||||
import org.eclipse.cdt.internal.core.model.TranslationUnit;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.refactoring.DocumentAdapter;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.UndoCTextFileChange;
|
||||
|
||||
|
@ -69,8 +71,8 @@ public class CTextFileChange extends TextFileChange {
|
|||
protected IDocument acquireDocument(IProgressMonitor pm) throws CoreException {
|
||||
IDocument doc= super.acquireDocument(pm);
|
||||
if (++fAquireCount == 1) {
|
||||
if (fTranslationUnit != null && fWorkingCopy == null) {
|
||||
fWorkingCopy= fTranslationUnit.getWorkingCopy(null, DocumentAdapter.FACTORY);
|
||||
if (fTranslationUnit instanceof TranslationUnit && fWorkingCopy == null) {
|
||||
fWorkingCopy= ((TranslationUnit) fTranslationUnit).getWorkingCopy(null, DocumentAdapter.FACTORY);
|
||||
if (!fTranslationUnit.isOpen()) {
|
||||
fTranslationUnit.open(null);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue