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

Added visitor support for the C Model.

This commit is contained in:
Doug Schaefer 2004-01-20 16:37:18 +00:00
parent a38f5c4f0d
commit 14bf87311d
3 changed files with 51 additions and 0 deletions

View file

@ -6,6 +6,7 @@ package org.eclipse.cdt.core.model;
*/ */
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
@ -313,4 +314,12 @@ public interface ICElement extends IAdaptable {
* exception occurs while accessing its corresponding resource * exception occurs while accessing its corresponding resource
*/ */
boolean isStructureKnown() throws CModelException; boolean isStructureKnown() throws CModelException;
/**
* Accept a visitor and walk the ICElement tree with it.
*
* @param visitor
* @throws CModelException
*/
void accept(ICElementVisitor visitor) throws CoreException;
} }

View file

@ -0,0 +1,24 @@
package org.eclipse.cdt.core.model;
import org.eclipse.core.runtime.CoreException;
/*
* (c) Copyright IBM Corp. 2004.
* All Rights Reserved.
*/
/**
* This interface is implemented by clients that walk the ICElement tree.
*/
public interface ICElementVisitor {
/**
* Visited a member if the ICElement tree. Returns whether to visit the children
* of this element.
*
* @param element
* @return
*/
public boolean visit(ICElement element) throws CoreException;
}

View file

@ -6,12 +6,14 @@ package org.eclipse.cdt.internal.core.model;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICElementVisitor;
import org.eclipse.cdt.core.model.ICModel; import org.eclipse.cdt.core.model.ICModel;
import org.eclipse.cdt.core.model.ICModelStatusConstants; import org.eclipse.cdt.core.model.ICModelStatusConstants;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IOpenable; import org.eclipse.cdt.core.model.IOpenable;
import org.eclipse.cdt.core.model.IParent; import org.eclipse.cdt.core.model.IParent;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
@ -383,4 +385,20 @@ public abstract class CElement extends PlatformObject implements ICElement {
return this.equals(otherElement); return this.equals(otherElement);
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.model.ICElement#accept(org.eclipse.cdt.core.model.ICElementVisitor)
*/
public void accept(ICElementVisitor visitor) throws CoreException {
// Visit me, return right away if the visitor doesn't want to visit my children
if (!visitor.visit(this))
return;
// If I am a Parent, visit my children
if (this instanceof IParent) {
ICElement [] children = ((IParent)this).getChildren();
for (int i = 0; i < children.length; ++i)
children[i].accept(visitor);
}
}
} }