1 package net.sourceforge.phpeclipse.builder;
3 import net.sourceforge.phpdt.internal.ui.util.PHPFileUtil;
4 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
5 import net.sourceforge.phpeclipse.phpeditor.PHPParserAction;
7 import org.eclipse.core.resources.IFile;
8 import org.eclipse.core.resources.IProject;
9 import org.eclipse.core.resources.IResource;
10 import org.eclipse.core.resources.IResourceDelta;
11 import org.eclipse.core.resources.IResourceDeltaVisitor;
12 import org.eclipse.core.runtime.CoreException;
13 import org.eclipse.core.runtime.IProgressMonitor;
14 import org.eclipse.core.runtime.OperationCanceledException;
18 * @see org.eclipse.core.resources.IResourceDelta
19 * @see org.eclipse.core.resources.IResourceDeltaVisitor
21 public class ParserVisitor implements IResourceDeltaVisitor {
22 final IProgressMonitor fMonitor;
23 final IProject fProject;
24 public ParserVisitor(IProject iProject, IProgressMonitor monitor) {
29 protected void checkCancel() {
30 if (fMonitor.isCanceled()) {
31 throw new OperationCanceledException();
36 * Visits the given resource delta.
38 * @return <code>true</code> if the resource delta's children should
39 * be visited; <code>false</code> if they should be skipped.
40 * @exception CoreException if the visit fails for some reason.
42 public boolean visit(IResourceDelta delta) throws CoreException {
44 IResource resource = delta.getResource();
45 int resourceType = resource.getType();
48 final IdentifierIndexManager indexManager = PHPeclipsePlugin.getDefault().getIndexManager(fProject);
50 switch (delta.getKind()) {
51 case IResourceDelta.ADDED :
52 if (resourceType == IResource.FILE) {
53 if ((resource.getFileExtension() != null) && PHPFileUtil.isPHPFile((IFile) resource)) {
55 fMonitor.subTask("Adding: " + resource.getFullPath());
57 // check for parsing errors
58 PHPParserAction.parseFile((IFile) resource);
59 // update indexfile for the project:
60 indexManager.addFile((IFile) resource);
65 case IResourceDelta.CHANGED :
66 if (resourceType == IResource.FILE) {
67 if ((resource.getFileExtension() != null) && PHPFileUtil.isPHPFile((IFile) resource)) {
69 fMonitor.subTask("Changing: " + resource.getFullPath());
71 //check for parsing errors
72 PHPParserAction.parseFile((IFile) resource);
73 // update indexfile for the project:
74 indexManager.changeFile((IFile) resource);
79 case IResourceDelta.REMOVED :
80 if (resourceType == IResource.FILE) {
81 if ((resource.getFileExtension() != null) && PHPFileUtil.isPHPFile((IFile) resource)) {
83 fMonitor.subTask("Removing: " + resource.getFullPath());
85 // update indexfile for the project:
86 indexManager.removeFile((IFile) resource);
91 return true; // carry on