From d6b9097bd54af28d1eee9e7df8d641e90d5a917e Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Fri, 11 Feb 2005 00:48:11 +0000 Subject: [PATCH] 2005-02-10 Alain Magloire Second 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 * model/org/eclipse/cdt/internal/core/model/PathEntryManager.java --- core/org.eclipse.cdt.core/ChangeLog | 7 ++ .../model/IPathEntryContainerExtension.java | 12 ++++ .../IPathEntryContainerExtensionListener.java | 19 +++++ .../core/model/PathEntryContainerChanged.java | 71 +++++++++++++++++++ .../internal/core/model/PathEntryManager.java | 50 ++++++++++++- 5 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IPathEntryContainerExtensionListener.java create mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/PathEntryContainerChanged.java diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog index 589df5abce8..8f3449dd22a 100644 --- a/core/org.eclipse.cdt.core/ChangeLog +++ b/core/org.eclipse.cdt.core/ChangeLog @@ -1,3 +1,10 @@ +2005-02-10 Alain Magloire + Second 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 + * model/org/eclipse/cdt/internal/core/model/PathEntryManager.java + 2005-02-10 Alain Magloire Part of the fix for 79596 * model/org/eclipse/cdt/core/model/CoreModel.java 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 52a9336c274..909849a5ef3 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 @@ -37,4 +37,16 @@ public interface IPathEntryContainerExtension extends IPathEntryContainer { * @see IPathEntry */ 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 new file mode 100644 index 00000000000..03fec847083 --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IPathEntryContainerExtensionListener.java @@ -0,0 +1,19 @@ +/******************************************************************************* + * 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 new file mode 100644 index 00000000000..b252bb73b7f --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/PathEntryContainerChanged.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * 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; + +import java.util.EventObject; + +import org.eclipse.core.runtime.IPath; + +/** + */ +public class PathEntryContainerChanged extends EventObject { + + /** + * + */ + public static final int INCLUDE_CHANGED = 1; + + /** + * + */ + public static final int MACRO_CHANGED = 2; + + /** + * Comment for serialVersionUID + */ + private static final long serialVersionUID = 3257565105200705590L; + + int fType; + + /** + * @param source + */ + public PathEntryContainerChanged(IPath source, int type) { + super(source); + fType = type; + } + + /** + * Returns the affected path; + * @return path + */ + public IPath getPath() { + return (IPath)getSource(); + } + + /** + * whether or not the change affected the include paths + * @return + */ + public boolean isIncludeChange() { + return fType == INCLUDE_CHANGED; + } + + /** + * Whether or not the chage affected the macro entries + * @return + */ + public boolean isMacroChange() { + return fType == MACRO_CHANGED; + } + +} 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 6f975bd24b4..519af40515e 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 @@ -37,14 +37,17 @@ import org.eclipse.cdt.core.model.IElementChangedListener; import org.eclipse.cdt.core.model.IIncludeEntry; import org.eclipse.cdt.core.model.ILibraryEntry; import org.eclipse.cdt.core.model.IMacroEntry; +import org.eclipse.cdt.core.model.IOpenable; 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; import org.eclipse.cdt.core.model.IWorkingCopy; +import org.eclipse.cdt.core.model.PathEntryContainerChanged; import org.eclipse.cdt.core.model.PathEntryContainerInitializer; import org.eclipse.cdt.core.resources.IPathEntryStore; import org.eclipse.cdt.core.resources.IPathEntryStoreListener; @@ -74,7 +77,7 @@ import org.eclipse.core.runtime.jobs.Job; * @author alain * */ -public class PathEntryManager implements IPathEntryStoreListener, IElementChangedListener { +public class PathEntryManager implements IPathEntryStoreListener, IElementChangedListener, IPathEntryContainerExtensionListener { // PathEntry extension public final static String PATHENTRY_STORE_ID = "PathEntryStore"; //$NON-NLS-1$ @@ -861,6 +864,12 @@ 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) { @@ -1404,6 +1413,45 @@ 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