changes for new Action
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / builder / ParserVisitor.java
index 5dbc801..01c5902 100644 (file)
@@ -1,9 +1,11 @@
 package net.sourceforge.phpeclipse.builder;
 
 import net.sourceforge.phpdt.internal.ui.util.PHPFileUtil;
+import net.sourceforge.phpeclipse.PHPeclipsePlugin;
 import net.sourceforge.phpeclipse.phpeditor.PHPParserAction;
 
 import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.resources.IResourceDelta;
 import org.eclipse.core.resources.IResourceDeltaVisitor;
@@ -18,15 +20,18 @@ import org.eclipse.core.runtime.OperationCanceledException;
  */
 public class ParserVisitor implements IResourceDeltaVisitor {
   final IProgressMonitor fMonitor;
-  public ParserVisitor(IProgressMonitor monitor) {
+  final IProject fProject;
+  public ParserVisitor(IProject iProject, IProgressMonitor monitor) {
     fMonitor = monitor;
+    fProject = iProject;
   }
-  
-       protected void checkCancel() {
-                               if (fMonitor.isCanceled()) {
-                                        throw new OperationCanceledException();
-                               }
-                }
+
+  protected void checkCancel() {
+    if (fMonitor.isCanceled()) {
+      throw new OperationCanceledException();
+    }
+  }
+
   /** 
    * Visits the given resource delta.
    * 
@@ -38,33 +43,51 @@ public class ParserVisitor implements IResourceDeltaVisitor {
 
     IResource resource = delta.getResource();
     int resourceType = resource.getType();
-               checkCancel();
-               
+    checkCancel();
+
+    final IdentifierIndexManager indexManager = PHPeclipsePlugin.getDefault().getIndexManager(fProject);
+
     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());
+          if ((resource.getFileExtension() != null) && PHPFileUtil.isPHPFile((IFile) resource)) {
+            fMonitor.worked(1);
+            fMonitor.subTask("Adding: " + resource.getFullPath());
+
+            // check for parsing errors
             PHPParserAction.parseFile((IFile) resource);
+            // update indexfile for the project:
+            indexManager.addFile((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());
+          if ((resource.getFileExtension() != null) && PHPFileUtil.isPHPFile((IFile) resource)) {
+            fMonitor.worked(1);
+            fMonitor.subTask("Changing: " + resource.getFullPath());
+
+            //check for parsing errors
             PHPParserAction.parseFile((IFile) resource);
+            // update indexfile for the project:
+            indexManager.changeFile((IFile) resource);
           }
         }
         break;
 
       case IResourceDelta.REMOVED :
+        if (resourceType == IResource.FILE) {
+          if ((resource.getFileExtension() != null) && PHPFileUtil.isPHPFile((IFile) resource)) {
+            fMonitor.worked(1);
+            fMonitor.subTask("Removing: " + resource.getFullPath());
+
+            // update indexfile for the project:
+            indexManager.removeFile((IFile) resource);
+          }
         }
+        break;
+    }
     return true; // carry on
   }