1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 10:16:03 +02:00

2005-02-14 Alain Magloire

Part of 79596
	* model/org/eclipse/cdt/core/model/CoreModel.java
	* model/org/eclipse/cdt/core/model/IPathEntryContainerExtension.java
	* model/org/eclipse/cdt/core/model/IPathEntryContainerExtensionListener.java
	* model/org/eclipse/cdt/core/model/PathEntryContainerChanged.java
	* model/org/eclipse/cdt/internal/core/model/PathEntryManager.java
This commit is contained in:
Alain Magloire 2005-02-14 22:00:20 +00:00
parent ebdeb763c8
commit 073c4f893f
6 changed files with 121 additions and 99 deletions

View file

@ -1,5 +1,13 @@
2005-02-14 Alain Magloire
Part of 79596
* model/org/eclipse/cdt/core/model/CoreModel.java
* model/org/eclipse/cdt/core/model/IPathEntryContainerExtension.java
* model/org/eclipse/cdt/core/model/IPathEntryContainerExtensionListener.java
* model/org/eclipse/cdt/core/model/PathEntryContainerChanged.java
* model/org/eclipse/cdt/internal/core/model/PathEntryManager.java
2005-02-10 Alain Magloire 2005-02-10 Alain Magloire
Second of 79596 Second part of 79596
* model/org/eclipse/cdt/core/model/IPathEntryContainerExtension.java * model/org/eclipse/cdt/core/model/IPathEntryContainerExtension.java
* model/org/eclipse/cdt/core/model/IPathEntryContainerExtensionListener.java * model/org/eclipse/cdt/core/model/IPathEntryContainerExtensionListener.java
* model/org/eclipse/cdt/core/model/PathEntryContainerChanged.java * model/org/eclipse/cdt/core/model/PathEntryContainerChanged.java

View file

@ -671,6 +671,20 @@ public class CoreModel {
pathEntryManager.setPathEntryContainer(affectedProjects, container, monitor); pathEntryManager.setPathEntryContainer(affectedProjects, container, monitor);
} }
/**
* Helper method use by a pathentry container implementing <code>IPathEntryContainerExtension</code>
* It notify the model of changes.
* Note: the paths in the <code>PathEntryContainerChanged[]</code> array must be on
* source that the container was set too. If not the changes will be silently ignore.
*
* @param container
* @param changes array of changes.
* @param monitor progress monitor
*/
public void pathEntryContainerUpdates(IPathEntryContainerExtension container, PathEntryContainerChanged[] changes, IProgressMonitor monitor) {
pathEntryManager.pathEntryContainerUpdates(container, changes, monitor);
}
/** /**
* Sets the pathentries of this project using a list of entries. * Sets the pathentries of this project using a list of entries.
* <p> * <p>

View file

@ -38,15 +38,4 @@ public interface IPathEntryContainerExtension extends IPathEntryContainer {
*/ */
IMacroEntry[] getMacroEntries(IPath path); IMacroEntry[] getMacroEntries(IPath path);
/**
*
* @param listener
*/
void addContainerListener(IPathEntryContainerExtensionListener listener);
/**
*
* @param listener
*/
void removeContainerListener(IPathEntryContainerExtensionListener listener);
} }

View file

@ -1,19 +0,0 @@
/*******************************************************************************
* Copyright (c) 2000, 2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.model;
/**
*/
public interface IPathEntryContainerExtensionListener {
void pathEntryContainerChanged(PathEntryContainerChanged[] events);
}

View file

@ -11,36 +11,45 @@
package org.eclipse.cdt.core.model; package org.eclipse.cdt.core.model;
import java.util.EventObject;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
/** /**
*/ */
public class PathEntryContainerChanged extends EventObject { public class PathEntryContainerChanged {
/** /**
* * Change in the includes settings
*/ */
public static final int INCLUDE_CHANGED = 1; public static final int INCLUDE_CHANGED = 1;
/** /**
* * Change in the Macro
*/ */
public static final int MACRO_CHANGED = 2; public static final int MACRO_CHANGED = 2;
/**
* Type of changes
*/
int fType;
/**
* Affected file
*/
IPath fPath;
/** /**
* Comment for <code>serialVersionUID</code> * Comment for <code>serialVersionUID</code>
*/ */
private static final long serialVersionUID = 3257565105200705590L; private static final long serialVersionUID = 3257565105200705590L;
int fType;
/** /**
*
* @param source * @param source
* @param type
*/ */
public PathEntryContainerChanged(IPath source, int type) { public PathEntryContainerChanged(IPath source, int type) {
super(source); fPath = source;
fType = type; fType = type;
} }
@ -49,7 +58,15 @@ public class PathEntryContainerChanged extends EventObject {
* @return path * @return path
*/ */
public IPath getPath() { public IPath getPath() {
return (IPath)getSource(); return fPath;
}
/**
* Type of change.
* @return
*/
public int getType() {
return fType;
} }
/** /**

View file

@ -42,7 +42,6 @@ import org.eclipse.cdt.core.model.IOutputEntry;
import org.eclipse.cdt.core.model.IPathEntry; import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.cdt.core.model.IPathEntryContainer; import org.eclipse.cdt.core.model.IPathEntryContainer;
import org.eclipse.cdt.core.model.IPathEntryContainerExtension; import org.eclipse.cdt.core.model.IPathEntryContainerExtension;
import org.eclipse.cdt.core.model.IPathEntryContainerExtensionListener;
import org.eclipse.cdt.core.model.IProjectEntry; import org.eclipse.cdt.core.model.IProjectEntry;
import org.eclipse.cdt.core.model.ISourceEntry; import org.eclipse.cdt.core.model.ISourceEntry;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
@ -77,7 +76,7 @@ import org.eclipse.core.runtime.jobs.Job;
* @author alain * @author alain
* *
*/ */
public class PathEntryManager implements IPathEntryStoreListener, IElementChangedListener, IPathEntryContainerExtensionListener { public class PathEntryManager implements IPathEntryStoreListener, IElementChangedListener {
// PathEntry extension // PathEntry extension
public final static String PATHENTRY_STORE_ID = "PathEntryStore"; //$NON-NLS-1$ public final static String PATHENTRY_STORE_ID = "PathEntryStore"; //$NON-NLS-1$
@ -101,6 +100,8 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
static final IMacroEntry[] NO_MACROENTRIES = new IMacroEntry[0]; static final IMacroEntry[] NO_MACROENTRIES = new IMacroEntry[0];
static final IPathEntryContainer[] NO_PATHENTRYCONTAINERS = new IPathEntryContainer[0];
// Synchronized the access of the cache entries. // Synchronized the access of the cache entries.
protected Map resolvedMap = new Hashtable(); protected Map resolvedMap = new Hashtable();
@ -182,12 +183,10 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
} }
} }
IPathEntryContainer[] containers = getPathEntryContainers(cproject); IPathEntryContainer[] containers = getPathEntryContainers(cproject);
if (containers != null) { for (int i = 0; i < containers.length; ++i) {
for (int i = 0; i < containers.length; ++i) { if (containers[i] instanceof IPathEntryContainerExtension) {
if (containers[i] instanceof IPathEntryContainerExtension) { IIncludeEntry[] incs = ((IPathEntryContainerExtension)containers[i]).getIncludeEntries(resPath);
IIncludeEntry[] incs = ((IPathEntryContainerExtension)containers[i]).getIncludeEntries(resPath); includeList.addAll(Arrays.asList(incs));
includeList.addAll(Arrays.asList(incs));
}
} }
} }
@ -259,12 +258,10 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
} }
} }
IPathEntryContainer[] containers = getPathEntryContainers(cproject); IPathEntryContainer[] containers = getPathEntryContainers(cproject);
if (containers != null) { for (int i = 0; i < containers.length; ++i) {
for (int i = 0; i < containers.length; ++i) { if (containers[i] instanceof IPathEntryContainerExtension) {
if (containers[i] instanceof IPathEntryContainerExtension) { IMacroEntry[] incs = ((IPathEntryContainerExtension)containers[i]).getMacroEntries(resPath);
IMacroEntry[] incs = ((IPathEntryContainerExtension)containers[i]).getMacroEntries(resPath); macroList.addAll(Arrays.asList(incs));
macroList.addAll(Arrays.asList(incs));
}
} }
} }
@ -673,10 +670,12 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
} }
containerPut(affectedProject, containerPath, newContainer); containerPut(affectedProject, containerPath, newContainer);
} }
// Nothing change. // Nothing change.
if (remaining == 0) { if (remaining == 0) {
return; return;
} }
// trigger model refresh // trigger model refresh
try { try {
//final boolean canChangeResources = //final boolean canChangeResources =
@ -719,7 +718,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
} }
public synchronized IPathEntryContainer[] getPathEntryContainers(ICProject cproject) { public synchronized IPathEntryContainer[] getPathEntryContainers(ICProject cproject) {
IPathEntryContainer[] pcs = null; IPathEntryContainer[] pcs = NO_PATHENTRYCONTAINERS;
Map projectContainers = (Map)Containers.get(cproject); Map projectContainers = (Map)Containers.get(cproject);
if (projectContainers != null) { if (projectContainers != null) {
Collection collection = projectContainers.values(); Collection collection = projectContainers.values();
@ -864,18 +863,71 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
oldContainer.notifyAll(); oldContainer.notifyAll();
} }
} }
if (oldContainer instanceof IPathEntryContainerExtension) {
((IPathEntryContainerExtension)oldContainer).removeContainerListener(this);
}
if (container instanceof IPathEntryContainerExtension) {
((IPathEntryContainerExtension)container).addContainerListener(this);
}
} }
private synchronized void containerRemove(ICProject cproject) { private synchronized void containerRemove(ICProject cproject) {
Containers.remove(cproject); Containers.remove(cproject);
} }
public void pathEntryContainerUpdates(IPathEntryContainerExtension container, PathEntryContainerChanged[] events, IProgressMonitor monitor) {
ArrayList list = new ArrayList(events.length);
for (int i = 0; i < events.length; ++i) {
PathEntryContainerChanged event = events[i];
ICElement celement = CoreModel.getDefault().create(event.getPath());
if (celement != null) {
// Sanity check the container __must__ be set on the project.
boolean foundContainer = false;
IPathEntryContainer[] containers = getPathEntryContainers(celement.getCProject());
for (int k = 0 ; k < containers.length; ++k) {
if (containers[k].getPath().equals(container.getPath())) {
foundContainer = true;
break;
}
}
if (!foundContainer) {
continue;
}
// remove the element info caching.
if (celement instanceof IOpenable) {
try {
((IOpenable)celement).close();
} catch (CModelException e) {
// ignore.
}
}
int flag =0;
if (event.isIncludeChange()) {
flag = ICElementDelta.F_CHANGED_PATHENTRY_INCLUDE;
} else if (event.isMacroChange()) {
flag = ICElementDelta.F_CHANGED_PATHENTRY_MACRO;
}
CElementDelta delta = new CElementDelta(celement.getCModel());
delta.changed(celement, flag);
list.add(delta);
}
}
if (list.size() > 0) {
final ICElementDelta[] deltas = new ICElementDelta[list.size()];
list.toArray(deltas);
try {
CoreModel.run(new IWorkspaceRunnable() {
public void run(IProgressMonitor progressMonitor) throws CoreException {
CModelManager manager = CModelManager.getDefault();
for (int i = 0; i < deltas.length; i++) {
manager.registerCModelDelta(deltas[i]);
}
manager.fire(ElementChangedEvent.POST_CHANGE);
}
}, monitor);
} catch (CoreException e) {
// log the error.
}
}
}
public String[] projectPrerequisites(IPathEntry[] entries) throws CModelException { public String[] projectPrerequisites(IPathEntry[] entries) throws CModelException {
if (entries != null) { if (entries != null) {
ArrayList prerequisites = new ArrayList(); ArrayList prerequisites = new ArrayList();
@ -1413,45 +1465,6 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
return false; return false;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.model.IPathEntryContainerExtensionListener#pathEntryContainerChanged(org.eclipse.cdt.core.model.PathEntryContainerChanged[])
*/
public void pathEntryContainerChanged(PathEntryContainerChanged[] events) {
ArrayList list = new ArrayList(events.length);
for (int i = 0; i < events.length; ++i) {
PathEntryContainerChanged event = events[i];
ICElement celement = CoreModel.getDefault().create(event.getPath());
if (celement != null) {
if (celement instanceof IOpenable) {
try {
((IOpenable)celement).close();
} catch (CModelException e) {
// ignore.
}
}
int flag =0;
if (event.isIncludeChange()) {
flag = ICElementDelta.F_CHANGED_PATHENTRY_INCLUDE;
} else if (event.isMacroChange()) {
flag = ICElementDelta.F_CHANGED_PATHENTRY_MACRO;
}
CElementDelta delta = new CElementDelta(celement.getCModel());
delta.changed(celement, flag);
list.add(delta);
}
}
if (list.size() > 0) {
ICElementDelta[] deltas = new ICElementDelta[list.size()];
list.toArray(deltas);
CModelManager manager = CModelManager.getDefault();
for (int i = 0; i < deltas.length; i++) {
manager.registerCModelDelta(deltas[i]);
}
manager.fire(ElementChangedEvent.POST_CHANGE);
}
}
protected IPathEntry cloneEntry(IPath rpath, IPathEntry entry) { protected IPathEntry cloneEntry(IPath rpath, IPathEntry entry) {
// get the path // get the path