From 073c4f893fbf17c1663f2d4953e417d71eea1f11 Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Mon, 14 Feb 2005 22:00:20 +0000 Subject: [PATCH] 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 --- core/org.eclipse.cdt.core/ChangeLog | 10 +- .../org/eclipse/cdt/core/model/CoreModel.java | 14 ++ .../model/IPathEntryContainerExtension.java | 11 -- .../IPathEntryContainerExtensionListener.java | 19 --- .../core/model/PathEntryContainerChanged.java | 33 +++-- .../internal/core/model/PathEntryManager.java | 133 ++++++++++-------- 6 files changed, 121 insertions(+), 99 deletions(-) delete mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IPathEntryContainerExtensionListener.java diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog index 8f3449dd22a..b78d389a1d8 100644 --- a/core/org.eclipse.cdt.core/ChangeLog +++ b/core/org.eclipse.cdt.core/ChangeLog @@ -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 diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java index 6e560641257..20bb3101dde 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java @@ -671,6 +671,20 @@ public class CoreModel { pathEntryManager.setPathEntryContainer(affectedProjects, container, monitor); } + /** + * Helper method use by a pathentry container implementing IPathEntryContainerExtension + * It notify the model of changes. + * Note: the paths in the PathEntryContainerChanged[] 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. *

diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IPathEntryContainerExtension.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IPathEntryContainerExtension.java index 909849a5ef3..397e6fc5ef7 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IPathEntryContainerExtension.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IPathEntryContainerExtension.java @@ -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); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IPathEntryContainerExtensionListener.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IPathEntryContainerExtensionListener.java deleted file mode 100644 index 03fec847083..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IPathEntryContainerExtensionListener.java +++ /dev/null @@ -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); -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/PathEntryContainerChanged.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/PathEntryContainerChanged.java index b252bb73b7f..23d0ce39c81 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/PathEntryContainerChanged.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/PathEntryContainerChanged.java @@ -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 serialVersionUID */ 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; } /** diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java index 519af40515e..8016ae3ef54 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java @@ -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