1 package net.sourceforge.phpdt.internal.core.builder;
3 import net.sourceforge.phpdt.internal.ui.util.PHPFileUtil;
4 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
5 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
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;
24 final IProject fProject;
26 public ParserVisitor(IProject iProject, IProgressMonitor monitor) {
31 protected void checkCancel() {
32 if (fMonitor.isCanceled()) {
33 throw new OperationCanceledException();
38 * Visits the given resource delta.
40 * @return <code>true</code> if the resource delta's children should be
41 * visited; <code>false</code> if they should be skipped.
42 * @exception CoreException
43 * if the visit fails for some reason.
45 public boolean visit(IResourceDelta delta) throws CoreException {
47 IResource resource = delta.getResource();
48 int resourceType = resource.getType();
51 final IdentifierIndexManager indexManager = PHPeclipsePlugin
52 .getDefault().getIndexManager(fProject);
54 switch (delta.getKind()) {
55 case IResourceDelta.ADDED:
56 if (resourceType == IResource.FILE) {
57 if ((resource.getFileExtension() != null)
58 && PHPFileUtil.isPHPFile((IFile) resource)) {
60 fMonitor.subTask("Adding: " + resource.getFullPath());
62 // check for parsing errors
63 // PHPParserAction.parseFile((IFile) resource);
64 // update indexfile for the project:
65 indexManager.addFile((IFile) resource);
70 case IResourceDelta.CHANGED:
71 if (resourceType == IResource.FILE) {
72 if ((resource.getFileExtension() != null)
73 && PHPFileUtil.isPHPFile((IFile) resource)) {
75 fMonitor.subTask("Changing: " + resource.getFullPath());
77 // check for parsing errors
78 // PHPParserAction.parseFile((IFile) resource);
79 // update indexfile for the project:
80 indexManager.changeFile((IFile) resource);
85 case IResourceDelta.REMOVED:
86 if (resourceType == IResource.FILE) {
87 if ((resource.getFileExtension() != null)
88 && PHPFileUtil.isPHPFile((IFile) resource)) {
90 fMonitor.subTask("Removing: " + resource.getFullPath());
92 // update indexfile for the project:
93 indexManager.removeFile((IFile) resource);
98 return true; // carry on