mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +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:
parent
ebdeb763c8
commit
073c4f893f
6 changed files with 121 additions and 99 deletions
|
@ -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
|
||||
Second of 79596
|
||||
Second part of 79596
|
||||
* model/org/eclipse/cdt/core/model/IPathEntryContainerExtension.java
|
||||
* model/org/eclipse/cdt/core/model/IPathEntryContainerExtensionListener.java
|
||||
* model/org/eclipse/cdt/core/model/PathEntryContainerChanged.java
|
||||
|
|
|
@ -671,6 +671,20 @@ public class CoreModel {
|
|||
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.
|
||||
* <p>
|
||||
|
|
|
@ -38,15 +38,4 @@ public interface IPathEntryContainerExtension extends IPathEntryContainer {
|
|||
*/
|
||||
IMacroEntry[] getMacroEntries(IPath path);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param listener
|
||||
*/
|
||||
void addContainerListener(IPathEntryContainerExtensionListener listener);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param listener
|
||||
*/
|
||||
void removeContainerListener(IPathEntryContainerExtensionListener listener);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -11,36 +11,45 @@
|
|||
|
||||
package org.eclipse.cdt.core.model;
|
||||
|
||||
import java.util.EventObject;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
*
|
||||
* Change in the Macro
|
||||
*/
|
||||
public static final int MACRO_CHANGED = 2;
|
||||
|
||||
/**
|
||||
* Type of changes
|
||||
*/
|
||||
int fType;
|
||||
|
||||
/**
|
||||
* Affected file
|
||||
*/
|
||||
IPath fPath;
|
||||
|
||||
/**
|
||||
* Comment for <code>serialVersionUID</code>
|
||||
*/
|
||||
private static final long serialVersionUID = 3257565105200705590L;
|
||||
|
||||
int fType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param source
|
||||
* @param type
|
||||
*/
|
||||
public PathEntryContainerChanged(IPath source, int type) {
|
||||
super(source);
|
||||
fPath = source;
|
||||
fType = type;
|
||||
}
|
||||
|
||||
|
@ -49,7 +58,15 @@ public class PathEntryContainerChanged extends EventObject {
|
|||
* @return path
|
||||
*/
|
||||
public IPath getPath() {
|
||||
return (IPath)getSource();
|
||||
return fPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Type of change.
|
||||
* @return
|
||||
*/
|
||||
public int getType() {
|
||||
return fType;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -42,7 +42,6 @@ import org.eclipse.cdt.core.model.IOutputEntry;
|
|||
import org.eclipse.cdt.core.model.IPathEntry;
|
||||
import org.eclipse.cdt.core.model.IPathEntryContainer;
|
||||
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.ISourceEntry;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
|
@ -77,7 +76,7 @@ import org.eclipse.core.runtime.jobs.Job;
|
|||
* @author alain
|
||||
*
|
||||
*/
|
||||
public class PathEntryManager implements IPathEntryStoreListener, IElementChangedListener, IPathEntryContainerExtensionListener {
|
||||
public class PathEntryManager implements IPathEntryStoreListener, IElementChangedListener {
|
||||
|
||||
// PathEntry extension
|
||||
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 IPathEntryContainer[] NO_PATHENTRYCONTAINERS = new IPathEntryContainer[0];
|
||||
|
||||
// Synchronized the access of the cache entries.
|
||||
protected Map resolvedMap = new Hashtable();
|
||||
|
||||
|
@ -182,12 +183,10 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
|
|||
}
|
||||
}
|
||||
IPathEntryContainer[] containers = getPathEntryContainers(cproject);
|
||||
if (containers != null) {
|
||||
for (int i = 0; i < containers.length; ++i) {
|
||||
if (containers[i] instanceof IPathEntryContainerExtension) {
|
||||
IIncludeEntry[] incs = ((IPathEntryContainerExtension)containers[i]).getIncludeEntries(resPath);
|
||||
includeList.addAll(Arrays.asList(incs));
|
||||
}
|
||||
for (int i = 0; i < containers.length; ++i) {
|
||||
if (containers[i] instanceof IPathEntryContainerExtension) {
|
||||
IIncludeEntry[] incs = ((IPathEntryContainerExtension)containers[i]).getIncludeEntries(resPath);
|
||||
includeList.addAll(Arrays.asList(incs));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -259,12 +258,10 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
|
|||
}
|
||||
}
|
||||
IPathEntryContainer[] containers = getPathEntryContainers(cproject);
|
||||
if (containers != null) {
|
||||
for (int i = 0; i < containers.length; ++i) {
|
||||
if (containers[i] instanceof IPathEntryContainerExtension) {
|
||||
IMacroEntry[] incs = ((IPathEntryContainerExtension)containers[i]).getMacroEntries(resPath);
|
||||
macroList.addAll(Arrays.asList(incs));
|
||||
}
|
||||
for (int i = 0; i < containers.length; ++i) {
|
||||
if (containers[i] instanceof IPathEntryContainerExtension) {
|
||||
IMacroEntry[] incs = ((IPathEntryContainerExtension)containers[i]).getMacroEntries(resPath);
|
||||
macroList.addAll(Arrays.asList(incs));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -673,10 +670,12 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
|
|||
}
|
||||
containerPut(affectedProject, containerPath, newContainer);
|
||||
}
|
||||
|
||||
// Nothing change.
|
||||
if (remaining == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// trigger model refresh
|
||||
try {
|
||||
//final boolean canChangeResources =
|
||||
|
@ -719,7 +718,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
|
|||
}
|
||||
|
||||
public synchronized IPathEntryContainer[] getPathEntryContainers(ICProject cproject) {
|
||||
IPathEntryContainer[] pcs = null;
|
||||
IPathEntryContainer[] pcs = NO_PATHENTRYCONTAINERS;
|
||||
Map projectContainers = (Map)Containers.get(cproject);
|
||||
if (projectContainers != null) {
|
||||
Collection collection = projectContainers.values();
|
||||
|
@ -864,18 +863,71 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
|
|||
oldContainer.notifyAll();
|
||||
}
|
||||
}
|
||||
if (oldContainer instanceof IPathEntryContainerExtension) {
|
||||
((IPathEntryContainerExtension)oldContainer).removeContainerListener(this);
|
||||
}
|
||||
if (container instanceof IPathEntryContainerExtension) {
|
||||
((IPathEntryContainerExtension)container).addContainerListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void containerRemove(ICProject 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 {
|
||||
if (entries != null) {
|
||||
ArrayList prerequisites = new ArrayList();
|
||||
|
@ -1413,45 +1465,6 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
|
|||
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) {
|
||||
|
||||
// get the path
|
||||
|
|
Loading…
Add table
Reference in a new issue