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

fixed up IPathEntryStore and DefaultPathEntryStore

since its extends ICExtension we don't need to pass a project and the Defaultstore can now filter the descriptor
change events properly.
This commit is contained in:
David Inglis 2004-05-13 17:45:33 +00:00
parent 875523b31e
commit 1d01ed2ee5
5 changed files with 52 additions and 91 deletions

View file

@ -16,11 +16,11 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.eclipse.cdt.core.AbstractCExtension;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CDescriptorEvent;
import org.eclipse.cdt.core.ICDescriptor;
import org.eclipse.cdt.core.ICDescriptorListener;
import org.eclipse.cdt.core.ICExtensionReference;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICModelStatus;
@ -44,7 +44,7 @@ import org.w3c.dom.NodeList;
/**
* PathEntryStore
*/
public class PathEntryStore extends AbstractCExtension implements IPathEntryStore, ICDescriptorListener {
public class DefaultPathEntryStore implements IPathEntryStore, ICDescriptorListener {
static String PATH_ENTRY = "pathentry"; //$NON-NLS-1$
static String PATH_ENTRY_ID = "org.eclipse.cdt.core.pathentry"; //$NON-NLS-1$
@ -67,28 +67,29 @@ public class PathEntryStore extends AbstractCExtension implements IPathEntryStor
static final IPathEntry[] NO_PATHENTRIES = new IPathEntry[0];
List listeners;
IProject fProject;
/**
*
*/
public PathEntryStore() {
super();
public DefaultPathEntryStore(IProject project) {
fProject = project;
listeners = Collections.synchronizedList(new ArrayList());
// Register the Core Model on the Descriptor
// Manager, it needs to know about changes.
CCorePlugin.getDefault().getCDescriptorManager().addDescriptorListener(this);
}
public IPathEntry[] getRawPathEntries(IProject project) throws CoreException {
public IPathEntry[] getRawPathEntries() throws CoreException {
ArrayList pathEntries = new ArrayList();
ICDescriptor cdesc = CCorePlugin.getDefault().getCProjectDescription(project);
ICDescriptor cdesc = CCorePlugin.getDefault().getCProjectDescription(fProject);
Element element = cdesc.getProjectData(PATH_ENTRY_ID);
NodeList list = element.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
Node childNode = list.item(i);
if (childNode.getNodeType() == Node.ELEMENT_NODE) {
if (childNode.getNodeName().equals(PATH_ENTRY)) {
pathEntries.add(decodePathEntry(project, (Element) childNode));
pathEntries.add(decodePathEntry(fProject, (Element) childNode));
}
}
}
@ -96,11 +97,11 @@ public class PathEntryStore extends AbstractCExtension implements IPathEntryStor
return (IPathEntry[]) pathEntries.toArray(NO_PATHENTRIES);
}
public void setRawPathEntries(IProject project, IPathEntry[] newRawEntries) throws CoreException {
if (Arrays.equals(newRawEntries, getRawPathEntries(project))) {
public void setRawPathEntries(IPathEntry[] newRawEntries) throws CoreException {
if (Arrays.equals(newRawEntries, getRawPathEntries())) {
return;
}
ICDescriptor descriptor = CCorePlugin.getDefault().getCProjectDescription(project);
ICDescriptor descriptor = CCorePlugin.getDefault().getCProjectDescription(fProject);
Element rootElement = descriptor.getProjectData(PATH_ENTRY_ID);
// Clear out all current children
Node child = rootElement.getFirstChild();
@ -112,7 +113,7 @@ public class PathEntryStore extends AbstractCExtension implements IPathEntryStor
if (newRawEntries != null && newRawEntries.length > 0) {
// Serialize the include paths
Document doc = rootElement.getOwnerDocument();
encodePathEntries(project.getFullPath(), doc, rootElement, newRawEntries);
encodePathEntries(fProject.getFullPath(), doc, rootElement, newRawEntries);
}
descriptor.saveProjectData();
}
@ -239,7 +240,7 @@ public class PathEntryStore extends AbstractCExtension implements IPathEntryStor
// translate the project prefix.
IPath xmlPath = entries[i].getPath();
if (xmlPath == null) {
xmlPath = new Path("");
xmlPath = new Path(""); //$NON-NLS-1$
}
if (kind != IPathEntry.CDT_CONTAINER) {
// translate to project relative from absolute (unless a device path)
@ -346,10 +347,9 @@ public class PathEntryStore extends AbstractCExtension implements IPathEntryStor
public void descriptorChanged(CDescriptorEvent event) {
if (event.getType() == CDescriptorEvent.CDTPROJECT_CHANGED) {
ICDescriptor cdesc = event.getDescriptor();
if (cdesc != null) {
IProject project = cdesc.getProject();
if (cdesc != null && cdesc.getProject() == fProject){
// Call the listeners.
fireContentChangedEvent(project);
fireContentChangedEvent(fProject);
}
}
}
@ -368,10 +368,7 @@ public class PathEntryStore extends AbstractCExtension implements IPathEntryStor
listeners.remove(listener);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.resources.IPathEntryStore#fireContentChangedEvent(IProject)
*/
public void fireContentChangedEvent(IProject project) {
private void fireContentChangedEvent(IProject project) {
PathEntryStoreChangedEvent evt = new PathEntryStoreChangedEvent(this, project, PathEntryStoreChangedEvent.CONTENT_CHANGED);
IPathEntryStoreListener[] observers = new IPathEntryStoreListener[listeners.size()];
listeners.toArray(observers);
@ -383,13 +380,21 @@ public class PathEntryStore extends AbstractCExtension implements IPathEntryStor
/* (non-Javadoc)
* @see org.eclipse.cdt.core.resources.IPathEntryStore#fireClosedChangedEvent(IProject)
*/
public void fireClosedEvent(IProject project) {
PathEntryStoreChangedEvent evt = new PathEntryStoreChangedEvent(this, project, PathEntryStoreChangedEvent.STORE_CLOSED);
public void close() {
PathEntryStoreChangedEvent evt = new PathEntryStoreChangedEvent(this, fProject, PathEntryStoreChangedEvent.STORE_CLOSED);
IPathEntryStoreListener[] observers = new IPathEntryStoreListener[listeners.size()];
listeners.toArray(observers);
for (int i = 0; i < observers.length; i++) {
observers[i].pathEntryStoreChanged(evt);
}
}
CCorePlugin.getDefault().getCDescriptorManager().removeDescriptorListener(this);
}
public IProject getProject() {
return fProject;
}
public ICExtensionReference getExtensionReference() {
return null;
}
}

View file

@ -288,8 +288,8 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
}
IPathEntry[] pathEntries;
try {
IPathEntryStore store = getPathEntryStore(project);
pathEntries = store.getRawPathEntries(project);
IPathEntryStore store = getPathEntryStore(project, true);
pathEntries = store.getRawPathEntries();
} catch (CoreException e) {
throw new CModelException(e);
}
@ -528,8 +528,8 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
public void saveRawPathEntries(ICProject cproject, IPathEntry[] newRawEntries) throws CModelException {
try {
IProject project = cproject.getProject();
IPathEntryStore store = getPathEntryStore(project);
store.setRawPathEntries(project, newRawEntries);
IPathEntryStore store = getPathEntryStore(project, true);
store.setRawPathEntries(newRawEntries);
} catch (CoreException e) {
throw new CModelException(e);
}
@ -681,9 +681,9 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
return containerIDs;
}
private synchronized IPathEntryStore getPathEntryStore(IProject project) throws CoreException {
private synchronized IPathEntryStore getPathEntryStore(IProject project, boolean create) throws CoreException {
IPathEntryStore store = (IPathEntryStore)storeMap.get(project);
if (store == null) {
if (store == null && create == true) {
store = CCorePlugin.getDefault().getPathEntryStore(project);
storeMap.put(project, store);
store.addPathEntryStoreListener(this);
@ -691,8 +691,11 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
return store;
}
private synchronized Object removePathEntryStore(IProject project) {
return storeMap.remove(project);
private synchronized void removePathEntryStore(IProject project) {
IPathEntryStore store = (IPathEntryStore)storeMap.remove(project);
if (store!= null) {
store.removePathEntryStoreListener(this);
}
}
/* (non-Javadoc)
@ -708,17 +711,9 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
CModelManager manager = CModelManager.getDefault();
ICProject cproject = manager.create(project);
try {
IPathEntryStore store = getPathEntryStore(project);
if (store != null) {
if (event.hasClosed()) {
removePathEntryStore(project);
store.removePathEntryStoreListener(this);
containerRemove(cproject);
}
}
} catch (CoreException e) {
CCorePlugin.log(e);
if (event.hasClosed()) {
removePathEntryStore(project);
containerRemove(cproject);
}
if (project.isAccessible()) {
try {
@ -766,9 +761,9 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
IProject project = cproject.getProject();
IPathEntryStore store = null;
try {
store = getPathEntryStore(project);
store = getPathEntryStore(project, false);
if (store != null) {
store.fireClosedEvent(project);
store.close();
}
} catch (CoreException e) {
throw new CModelException(e);

View file

@ -97,19 +97,6 @@
</run>
</cextension>
</extension>
<!-- =================================================================================== -->
<!-- Define the default PathEntry store provided by the CDT -->
<!-- =================================================================================== -->
<extension
id="cdtPathEntryStore"
name="Path Entry Store"
point="org.eclipse.cdt.core.PathEntryStore">
<cextension>
<run
class="org.eclipse.cdt.internal.core.model.PathEntryStore">
</run>
</cextension>
</extension>
<!-- =================================================================================== -->
<!-- Define the list of Error Parser provided by the CDT -->

View file

@ -31,6 +31,7 @@ import org.eclipse.cdt.internal.core.CDTLogWriter;
import org.eclipse.cdt.internal.core.CDescriptorManager;
import org.eclipse.cdt.internal.core.model.BufferManager;
import org.eclipse.cdt.internal.core.model.CModelManager;
import org.eclipse.cdt.internal.core.model.DefaultPathEntryStore;
import org.eclipse.cdt.internal.core.model.DeltaProcessor;
import org.eclipse.cdt.internal.core.model.IBufferFactory;
import org.eclipse.cdt.internal.core.model.Util;
@ -650,28 +651,13 @@ public class CCorePlugin extends Plugin {
}
}
if (store == null) {
store = getDefaultPathEntryStore();
store = getDefaultPathEntryStore(project);
}
return store;
}
public IPathEntryStore getDefaultPathEntryStore() throws CoreException {
IPathEntryStore store = null;
IExtensionPoint extensionPoint = getDescriptor().getExtensionPoint(PATHENTRY_STORE_ID);
IExtension extension = extensionPoint.getExtension(DEFAULT_PATHENTRY_STORE_ID);
if (extension != null) {
IConfigurationElement element[] = extension.getConfigurationElements();
for (int i = 0; i < element.length; i++) {
if (element[i].getName().equalsIgnoreCase("cextension")) { //$NON-NLS-1$
store = (IPathEntryStore) element[i].createExecutableExtension("run"); //$NON-NLS-1$
break;
}
}
} else {
IStatus s = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, CCorePlugin.getResourceString("CCorePlugin.exception.noBinaryFormat"), null); //$NON-NLS-1$
throw new CoreException(s);
}
return store;
public IPathEntryStore getDefaultPathEntryStore(IProject project) throws CoreException {
return new DefaultPathEntryStore(project);
}
/**

View file

@ -11,14 +11,14 @@
package org.eclipse.cdt.core.resources;
import org.eclipse.cdt.core.ICExtension;
import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
/**
* IPathEntryStore
*/
public interface IPathEntryStore {
public interface IPathEntryStore extends ICExtension {
/**
* Returns the path entries save on the project.
@ -26,7 +26,7 @@ public interface IPathEntryStore {
* @return
* @throws CoreException
*/
IPathEntry[] getRawPathEntries(IProject project) throws CoreException;
IPathEntry[] getRawPathEntries() throws CoreException;
/**
* Save the entries on the project.
@ -37,7 +37,7 @@ public interface IPathEntryStore {
* @param entries
* @throws CoreException
*/
void setRawPathEntries(IProject project, IPathEntry[] entries) throws CoreException;
void setRawPathEntries(IPathEntry[] entries) throws CoreException;
/**
* Add a listener to the store.
@ -53,18 +53,6 @@ public interface IPathEntryStore {
*/
void removePathEntryStoreListener(IPathEntryStoreListener listener);
/**
* Fire a CONTENT_CHANGED event to the listeners.
*
* @param project
*/
void fireContentChangedEvent(IProject project);
/**
* Fire a CLOSE_STORE event to the listeners.
*
* @param project
*/
void fireClosedEvent(IProject project);
void close();
}