1 package net.sourceforge.phpeclipse.builder;
3 import net.sourceforge.phpdt.internal.ui.util.PHPFileUtil;
4 import net.sourceforge.phpeclipse.phpeditor.PHPParserAction;
6 import org.eclipse.core.resources.IFile;
7 import org.eclipse.core.resources.IResource;
8 import org.eclipse.core.resources.IResourceDelta;
9 import org.eclipse.core.resources.IResourceDeltaVisitor;
10 import org.eclipse.core.runtime.CoreException;
11 import org.eclipse.core.runtime.IProgressMonitor;
12 import org.eclipse.core.runtime.OperationCanceledException;
16 * @see org.eclipse.core.resources.IResourceDelta
17 * @see org.eclipse.core.resources.IResourceDeltaVisitor
19 public class ParserVisitor implements IResourceDeltaVisitor {
20 final IProgressMonitor fMonitor;
21 public ParserVisitor(IProgressMonitor monitor) {
25 protected void checkCancel() {
26 if (fMonitor.isCanceled()) {
27 throw new OperationCanceledException();
31 * Visits the given resource delta.
33 * @return <code>true</code> if the resource delta's children should
34 * be visited; <code>false</code> if they should be skipped.
35 * @exception CoreException if the visit fails for some reason.
37 public boolean visit(IResourceDelta delta) throws CoreException {
39 IResource resource = delta.getResource();
40 int resourceType = resource.getType();
43 switch (delta.getKind()) {
44 case IResourceDelta.ADDED :
45 if (resourceType == IResource.FILE) {
46 if ((resource.getFileExtension() != null)
47 && PHPFileUtil.isPHPFile((IFile) resource)) {
49 fMonitor.subTask("Parsing: " + resource.getFullPath());
50 PHPParserAction.parseFile((IFile) resource);
55 case IResourceDelta.CHANGED :
56 if (resourceType == IResource.FILE) {
57 if ((resource.getFileExtension() != null)
58 && PHPFileUtil.isPHPFile((IFile) resource)) {
60 fMonitor.subTask("Parsing: " + resource.getFullPath());
61 PHPParserAction.parseFile((IFile) resource);
66 case IResourceDelta.REMOVED :
68 return true; // carry on