package net.sourceforge.phpeclipse.builder;
import net.sourceforge.phpdt.internal.ui.util.PHPFileUtil;
import net.sourceforge.phpeclipse.phpeditor.PHPParserAction;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
/**
*
* @see org.eclipse.core.resources.IResourceDelta
* @see org.eclipse.core.resources.IResourceDeltaVisitor
*/
public class ParserVisitor implements IResourceDeltaVisitor {
final IProgressMonitor fMonitor;
public ParserVisitor(IProgressMonitor monitor) {
fMonitor = monitor;
}
protected void checkCancel() {
if (fMonitor.isCanceled()) {
throw new OperationCanceledException();
}
}
/**
* Visits the given resource delta.
*
* @return true
if the resource delta's children should
* be visited; false
if they should be skipped.
* @exception CoreException if the visit fails for some reason.
*/
public boolean visit(IResourceDelta delta) throws CoreException {
IResource resource = delta.getResource();
int resourceType = resource.getType();
checkCancel();
switch (delta.getKind()) {
case IResourceDelta.ADDED :
if (resourceType == IResource.FILE) {
if ((resource.getFileExtension() != null)
&& PHPFileUtil.isPHPFile((IFile) resource)) {
fMonitor.worked(1);
fMonitor.subTask("Parsing: " + resource.getFullPath());
PHPParserAction.parseFile((IFile) resource);
}
}
break;
case IResourceDelta.CHANGED :
if (resourceType == IResource.FILE) {
if ((resource.getFileExtension() != null)
&& PHPFileUtil.isPHPFile((IFile) resource)) {
fMonitor.worked(1);
fMonitor.subTask("Parsing: " + resource.getFullPath());
PHPParserAction.parseFile((IFile) resource);
}
}
break;
case IResourceDelta.REMOVED :
}
return true; // carry on
}
}