Extended the builder with an index file generator for PHP class- and function-names.
authorkhartlage <khartlage>
Mon, 8 Sep 2003 22:34:29 +0000 (22:34 +0000)
committerkhartlage <khartlage>
Mon, 8 Sep 2003 22:34:29 +0000 (22:34 +0000)
The index is stored in a "project.index" file for every project with php-nature.
Right-mouse click in the PHP editor on an indexed class- or function-name should open the file, where the identifier is declared.

16 files changed:
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/util/StreamUtil.java [new file with mode: 0644]
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/util/StringUtil.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPOpenDeclarationEditorActon.java [new file with mode: 0644]
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/ExternalEditorInput.java [new file with mode: 0644]
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/ExternalStorageDocumentProvider.java [new file with mode: 0644]
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/FileStorage.java [new file with mode: 0644]
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/IdentifierIndexManager.java [new file with mode: 0644]
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/PHPIdentifierLocation.java [new file with mode: 0644]
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/ParserBuilder.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/ParserVisitor.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/mover/obfuscator/PHPAnalyzer.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/mover/obfuscator/PHPIdentifier.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPParserAction.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/preferences/PHPObfuscatorPropertyPage.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/resourcesview/PHPProject.java

diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/util/StreamUtil.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/util/StreamUtil.java
new file mode 100644 (file)
index 0000000..cdfe20d
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Created on 06.09.2003
+ *
+ */
+package net.sourceforge.phpdt.internal.ui.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * @author khartlage
+ * */
+public class StreamUtil {
+  public static void transferStreams(InputStream source, OutputStream destination) throws IOException {
+    try {
+      byte[] buffer = new byte[8192];
+      while (true) {
+        int bytesRead = source.read(buffer);
+        if (bytesRead == -1)
+          break;
+        destination.write(buffer, 0, bytesRead);
+      }
+    } finally {
+      try {
+        source.close();
+      } catch (IOException e) {
+      }
+      try {
+        destination.close();
+      } catch (IOException e) {
+      }
+    }
+  }
+}
index cb16be2..a414fd1 100644 (file)
@@ -11,6 +11,11 @@ Contributors:
 **********************************************************************/
 package net.sourceforge.phpeclipse;
 
+import java.io.File;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+
 import net.sourceforge.phpdt.externaltools.internal.model.ColorManager;
 import net.sourceforge.phpdt.externaltools.internal.model.ExternalToolsPlugin;
 import net.sourceforge.phpdt.externaltools.internal.model.VariableContextManager;
@@ -18,6 +23,10 @@ import net.sourceforge.phpdt.internal.ui.preferences.TemplatePreferencePage;
 import net.sourceforge.phpdt.internal.ui.viewsupport.ImageDescriptorRegistry;
 import net.sourceforge.phpdt.ui.PreferenceConstants;
 import net.sourceforge.phpdt.ui.text.JavaTextTools;
+import net.sourceforge.phpeclipse.builder.ExternalEditorInput;
+import net.sourceforge.phpeclipse.builder.ExternalStorageDocumentProvider;
+import net.sourceforge.phpeclipse.builder.FileStorage;
+import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
 import net.sourceforge.phpeclipse.phpeditor.PHPDocumentProvider;
 import net.sourceforge.phpeclipse.phpeditor.PHPSyntaxRdr;
 import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
@@ -27,6 +36,7 @@ import net.sourceforge.phpeclipse.resourcesview.ResourceAdapterFactory;
 
 import org.eclipse.core.boot.BootLoader;
 import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.resources.IWorkspace;
 import org.eclipse.core.resources.ResourcesPlugin;
@@ -40,22 +50,30 @@ import org.eclipse.core.runtime.Platform;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.jface.preference.PreferenceConverter;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorDescriptor;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorRegistry;
+import org.eclipse.ui.IWorkbench;
 import org.eclipse.ui.IWorkbenchPage;
 import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.eclipse.ui.texteditor.IDocumentProvider;
+import org.eclipse.ui.texteditor.ITextEditor;
 
 /**
  * The main plugin class to be used in the desktop.
  */
 public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceConstants {
-
   /**
    * The id of the PHP plugin (value <code>"net.sourceforge.phpeclipse"</code>).
    */
   public static final String PLUGIN_ID = "net.sourceforge.phpeclipse"; //$NON-NLS-1$
-  public final static String PHP_NATURE_ID = PLUGIN_ID + ".phpnature";
 
   /** 
    * id of builder - matches plugin.xml (concatenate pluginid.builderid) 
@@ -63,27 +81,10 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceCon
   public static final String BUILDER_INDEX_ID = PLUGIN_ID + ".indexbuilder";
   public static final String BUILDER_PARSER_ID = PLUGIN_ID + ".parserbuilder";
 
-  // public static final String PHP_RESOURCES_VIEW_ID = PLUGIN_ID + ".resourcesview.ViewPHPResources"; //$NON-NLS-1$
-  public static final String PHP_CODING_ACTION_SET_ID = PLUGIN_ID + ".ui.CodingActionSet"; //$NON-NLS-1$
-
-  public static final String PHPPARSER_NEW = "test.PHPParser";
-  public static final String PHPPARSER_ORIGINAL = "net.sourceforge.phpdt.internal.compiler.parser.Parser";
-
-  /** Change this if you want to switch PHP Parser. */
-  public static final String PHPPARSER = PHPPARSER_ORIGINAL;
-
-  //The shared instance.
-  private static PHPeclipsePlugin plugin;
+  /** General debug flag*/
+  public static final boolean DEBUG = false;
 
   private static ExternalToolsPlugin externalTools;
-  //Resource bundle.
-  //private ResourceBundle resourceBundle;
-
-  private ImageDescriptorRegistry fImageDescriptorRegistry;
-  private PHPDocumentProvider fCompilationUnitDocumentProvider;
-  private IFile fLastEditorFile = null;
-
-  private JavaTextTools fJavaTextTools;
 
   /**
   * The Java virtual machine that we are running on.
@@ -102,17 +103,37 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceCon
   /** MRJ 3.1 */
   private static final int MRJ_3_1 = 4;
 
-  /** Windows NT  */
-  private static final int WINDOWS_NT = 5;
+  /** JVM constant for any other platform */
+  private static final int OTHER = -1;
+
+  // public static final String PHP_RESOURCES_VIEW_ID = PLUGIN_ID + ".resourcesview.ViewPHPResources"; //$NON-NLS-1$
+  public static final String PHP_CODING_ACTION_SET_ID = PLUGIN_ID + ".ui.CodingActionSet"; //$NON-NLS-1$
+  public final static String PHP_NATURE_ID = PLUGIN_ID + ".phpnature";
+
+  public static final String PHPPARSER_ORIGINAL = "net.sourceforge.phpdt.internal.compiler.parser.Parser";
+
+  /** Change this if you want to switch PHP Parser. */
+  public static final String PHPPARSER = PHPPARSER_ORIGINAL;
+
+  public static final String PHPPARSER_NEW = "test.PHPParser";
+
+  //The shared instance.
+  private static PHPeclipsePlugin plugin;
 
   /** Windows 9x  */
   private static final int WINDOWS_9x = 6;
 
-  /** JVM constant for any other platform */
-  private static final int OTHER = -1;
+  /** Windows NT  */
+  private static final int WINDOWS_NT = 5;
+  private PHPDocumentProvider fCompilationUnitDocumentProvider;
+  //Resource bundle.
+  //private ResourceBundle resourceBundle;
 
-  /** General debug flag*/
-  public static final boolean DEBUG = false;
+  private ImageDescriptorRegistry fImageDescriptorRegistry;
+  private HashMap fIndexManagerMap = new HashMap();
+
+  private JavaTextTools fJavaTextTools;
+  private IFile fLastEditorFile = null;
   /**
    * The constructor.
    */
@@ -128,63 +149,50 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceCon
     //    }
   }
 
-  public static ImageDescriptorRegistry getImageDescriptorRegistry() {
-    return getDefault().internalGetImageDescriptorRegistry();
+  public static IWorkbenchPage getActivePage() {
+    return getDefault().internalGetActivePage();
   }
 
-  private ImageDescriptorRegistry internalGetImageDescriptorRegistry() {
-    if (fImageDescriptorRegistry == null)
-      fImageDescriptorRegistry = new ImageDescriptorRegistry();
-    return fImageDescriptorRegistry;
-  }
-  // @TODO: refactor this into a better method name !
-  public synchronized PHPDocumentProvider getCompilationUnitDocumentProvider() {
-    if (fCompilationUnitDocumentProvider == null)
-      fCompilationUnitDocumentProvider = new PHPDocumentProvider();
-    return fCompilationUnitDocumentProvider;
+  public static Shell getActiveWorkbenchShell() {
+    return getActiveWorkbenchWindow().getShell();
   }
 
-  private static void setJVM() {
-    String osName = System.getProperty("os.name");
-
-    if (osName.startsWith("Mac OS")) {
-      String mrjVersion = System.getProperty("mrj.version");
-      String majorMRJVersion = mrjVersion.substring(0, 3);
-      jvm = OTHER;
-      try {
-
-        double version = Double.valueOf(majorMRJVersion).doubleValue();
-
-        if (version == 2) {
-          jvm = MRJ_2_0;
-        } else if (version >= 2.1 && version < 3) {
-          jvm = MRJ_2_1;
-        } else if (version == 3.0) {
-          jvm = MRJ_3_0;
-        } else if (version >= 3.1) {
-          jvm = MRJ_3_1;
-        }
-
-      } catch (NumberFormatException nfe) {
+  public static IWorkbenchWindow getActiveWorkbenchWindow() {
+    return getDefault().getWorkbench().getActiveWorkbenchWindow();
+  }
+  /**
+   * Returns the shared instance.
+   */
+  public static PHPeclipsePlugin getDefault() {
+    return plugin;
+  }
 
-      }
+  public static ImageDescriptorRegistry getImageDescriptorRegistry() {
+    return getDefault().internalGetImageDescriptorRegistry();
+  }
 
-    } else if (osName.startsWith("Windows")) {
-      if (osName.indexOf("9") != -1) {
-        jvm = WINDOWS_9x;
-      } else {
-        jvm = WINDOWS_NT;
-      }
-    }
+  static IPath getInstallLocation() {
+    return new Path(getDefault().getDescriptor().getInstallURL().getFile());
   }
   public static int getJVM() {
     return jvm;
   }
+
+  public static String getPluginId() {
+    return getDefault().getDescriptor().getUniqueIdentifier();
+  }
+
   /**
-   * Returns the shared instance.
+   * Returns the standard display to be used. The method first checks, if
+   * the thread calling this method has an associated display. If so, this
+   * display is returned. Otherwise the method returns the default display.
    */
-  public static PHPeclipsePlugin getDefault() {
-    return plugin;
+  public static Display getStandardDisplay() {
+    Display display = Display.getCurrent();
+    if (display == null) {
+      display = Display.getDefault();
+    }
+    return display;
   }
 
   //  public static ExternalToolsPlugin getExternalTools() {
@@ -197,31 +205,8 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceCon
     return ResourcesPlugin.getWorkspace();
   }
 
-  public static IWorkbenchPage getActivePage() {
-    return getDefault().internalGetActivePage();
-  }
-
-  private IWorkbenchPage internalGetActivePage() {
-    IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
-    if (window != null)
-      return window.getActivePage();
-    return null;
-  }
-
-  public static IWorkbenchWindow getActiveWorkbenchWindow() {
-    return getDefault().getWorkbench().getActiveWorkbenchWindow();
-  }
-
-  public static Shell getActiveWorkbenchShell() {
-    return getActiveWorkbenchWindow().getShell();
-  }
-
-  public static String getPluginId() {
-    return getDefault().getDescriptor().getUniqueIdentifier();
-  }
-
-  public static void log(IStatus status) {
-    getDefault().getLog().log(status);
+  public static boolean isDebug() {
+    return getDefault().isDebugging();
   }
 
   //  public static void logErrorMessage(String message) {
@@ -246,16 +231,69 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceCon
     Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, null);
     log(status);
   }
+
+  public static void log(IStatus status) {
+    getDefault().getLog().log(status);
+  }
   public static void log(Throwable e) {
     log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$
   }
 
-  public static boolean isDebug() {
-    return getDefault().isDebugging();
+  private static void setJVM() {
+    String osName = System.getProperty("os.name");
+
+    if (osName.startsWith("Mac OS")) {
+      String mrjVersion = System.getProperty("mrj.version");
+      String majorMRJVersion = mrjVersion.substring(0, 3);
+      jvm = OTHER;
+      try {
+
+        double version = Double.valueOf(majorMRJVersion).doubleValue();
+
+        if (version == 2) {
+          jvm = MRJ_2_0;
+        } else if (version >= 2.1 && version < 3) {
+          jvm = MRJ_2_1;
+        } else if (version == 3.0) {
+          jvm = MRJ_3_0;
+        } else if (version >= 3.1) {
+          jvm = MRJ_3_1;
+        }
+
+      } catch (NumberFormatException nfe) {
+
+      }
+
+    } else if (osName.startsWith("Windows")) {
+      if (osName.indexOf("9") != -1) {
+        jvm = WINDOWS_9x;
+      } else {
+        jvm = WINDOWS_NT;
+      }
+    }
   }
 
-  static IPath getInstallLocation() {
-    return new Path(getDefault().getDescriptor().getInstallURL().getFile());
+  // TODO: refactor this into a better method name !
+  public synchronized PHPDocumentProvider getCompilationUnitDocumentProvider() {
+    if (fCompilationUnitDocumentProvider == null)
+      fCompilationUnitDocumentProvider = new PHPDocumentProvider();
+    return fCompilationUnitDocumentProvider;
+  }
+
+  /**
+   * Get the identifier index manager for the given project
+   * 
+   * @param iProject the current project
+   * @return
+   */
+  public IdentifierIndexManager getIndexManager(IProject iProject) {
+    String indexFilename = iProject.getLocation() + File.separator + "project.index";
+    IdentifierIndexManager indexManager = (IdentifierIndexManager) fIndexManagerMap.get(indexFilename);
+    if (indexManager == null) {
+      indexManager = new IdentifierIndexManager(indexFilename);
+      fIndexManagerMap.put(indexFilename, indexManager);
+    }
+    return indexManager;
   }
 
   public synchronized JavaTextTools getJavaTextTools() {
@@ -264,6 +302,10 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceCon
     return fJavaTextTools;
   }
 
+  public IFile getLastEditorFile() {
+    return fLastEditorFile;
+  }
+
   /**
    * Returns the string from the plugin's resource bundle,
    * or 'key' if not found.
@@ -299,7 +341,7 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceCon
     } else if (windowsSystem.equals(BootLoader.WS_WIN32)) {
       store.setDefault(EXTERNAL_BROWSER_PREF, "rundll32 url.dll,FileProtocolHandler {0}");
     } else if (windowsSystem.equals(BootLoader.WS_CARBON)) {
-       // TODO How do we start Safari on Mac OS X ?
+      // TODO How do we start Safari on Mac OS X ?
       store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
     } else {
       store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
@@ -412,17 +454,115 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceCon
     externalTools.initializeDefaultPreferences(store);
   }
 
+  private IWorkbenchPage internalGetActivePage() {
+    IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
+    if (window != null)
+      return window.getActivePage();
+    return null;
+  }
+
+  private ImageDescriptorRegistry internalGetImageDescriptorRegistry() {
+    if (fImageDescriptorRegistry == null)
+      fImageDescriptorRegistry = new ImageDescriptorRegistry();
+    return fImageDescriptorRegistry;
+  }
+
   /**
-   * Returns the standard display to be used. The method first checks, if
-   * the thread calling this method has an associated display. If so, this
-   * display is returned. Otherwise the method returns the default display.
+       * Open a file in the Workbench that may or may not exist in the workspace.
+       * Must be run on the UI thread.
+       * @param filename
+       * @param line
+       * @throws CoreException
+       */
+  public void openFileInTextEditor(String filename, int line, String findString) throws CoreException {
+
+    // reject directories
+    if (new File(filename).isDirectory())
+      return;
+
+    IWorkbench workbench = PlatformUI.getWorkbench();
+    IWorkbenchWindow window = workbench.getWorkbenchWindows()[0];
+    IWorkbenchPage page = window.getActivePage();
+    IPath path = new Path(filename);
+
+    // If the file exists in the workspace, open it
+    IFile file = getWorkspace().getRoot().getFileForLocation(path);
+    IEditorPart editor;
+    ITextEditor textEditor;
+    if (file != null && file.exists()) {
+      editor = page.openEditor(file);
+      textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
+    } else {
+      // Otherwise open the stream directly
+      if (page == null)
+        return;
+      FileStorage storage = new FileStorage(path);
+      IEditorRegistry registry = getWorkbench().getEditorRegistry();
+      IEditorDescriptor desc = registry.getDefaultEditor(filename);
+      if (desc == null) {
+        desc = registry.getDefaultEditor();
+      }
+      IEditorInput input = new ExternalEditorInput(storage);
+      editor = page.openEditor(input, desc.getId());
+      textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
+
+      // If the storage provider is not ours, we can't guarantee read/write.
+      if (textEditor != null) {
+        IDocumentProvider documentProvider = textEditor.getDocumentProvider();
+        if (!(documentProvider instanceof ExternalStorageDocumentProvider)) {
+          storage.setReadOnly();
+        }
+      }
+    }
+    if (textEditor != null) {
+      // If a line number was given, go to it
+      if (line > 0) {
+        try {
+          line--; // document is 0 based
+          IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
+          textEditor.selectAndReveal(document.getLineOffset(line), document.getLineLength(line));
+
+        } catch (BadLocationException e) {
+          // invalid text position -> do nothing
+        }
+      }
+      //               If a string was given, go to it
+      if (findString != null) {
+        try {
+          IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
+          int offset = document.search(0, findString, true, false, true);
+          textEditor.selectAndReveal(offset, findString.length());
+
+        } catch (BadLocationException e) {
+          // invalid text position -> do nothing
+        }
+
+      }
+    }
+  }
+
+  public void setLastEditorFile(IFile textEditor) {
+    this.fLastEditorFile = textEditor;
+  }
+
+  /**
+   * @see org.eclipse.ui.plugin.AbstractUIPlugin#shutdown()
    */
-  public static Display getStandardDisplay() {
-    Display display = Display.getCurrent();
-    if (display == null) {
-      display = Display.getDefault();
+  public void shutdown() throws CoreException {
+               super.shutdown();
+               
+    //  externalTools.shutDown();
+    ColorManager.getDefault().dispose();
+
+    // save the information from the php index files if necessary
+    Collection collection = fIndexManagerMap.values();
+    Iterator iterator = collection.iterator();
+    IdentifierIndexManager indexManager = null;
+    while (iterator.hasNext()) {
+      indexManager = (IdentifierIndexManager) iterator.next();
+      indexManager.writeFile();
     }
-    return display;
+    
   }
 
   public void startup() throws CoreException {
@@ -439,19 +579,4 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceCon
     });
   }
 
-  /**
-   * @see org.eclipse.core.runtime.Plugin#shutdown()
-   */
-  public void shutdown() throws CoreException {
-    //  externalTools.shutDown();
-    ColorManager.getDefault().dispose();
-  }
-
-  public void setLastEditorFile(IFile textEditor) {
-    this.fLastEditorFile = textEditor;
-  }
-
-  public IFile getLastEditorFile() {
-    return fLastEditorFile;
-  }
 }
\ No newline at end of file
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPOpenDeclarationEditorActon.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPOpenDeclarationEditorActon.java
new file mode 100644 (file)
index 0000000..babeffc
--- /dev/null
@@ -0,0 +1,138 @@
+/**********************************************************************
+Copyright (c) 2000, 2002 IBM Corp. and others.
+All rights reserved. This program and the accompanying materials
+are made available under the terms of the Common Public License v1.0
+which accompanies this distribution, and is available at
+http://www.eclipse.org/legal/cpl-v10.html
+
+Contributors:
+    Klaus Hartlage - www.eclipseproject.de
+**********************************************************************/
+package net.sourceforge.phpeclipse.actions;
+
+import java.util.List;
+
+import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
+import net.sourceforge.phpeclipse.builder.PHPIdentifierLocation;
+import net.sourceforge.phpeclipse.phpeditor.PHPEditor;
+import net.sourceforge.phpeclipse.phpeditor.php.PHPWordExtractor;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.text.TextSelection;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.ui.IEditorActionDelegate;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.actions.ActionDelegate;
+
+public class PHPOpenDeclarationEditorActon extends ActionDelegate implements IEditorActionDelegate {
+
+  private IWorkbenchWindow fWindow;
+  private PHPEditor fEditor;
+  private IProject fProject;
+
+  public void dispose() {
+  }
+
+  public void init(IWorkbenchWindow window) {
+    this.fWindow = window;
+  }
+
+  public void selectionChanged(IAction action, ISelection selection) {
+    if (!selection.isEmpty()) {
+      if (selection instanceof TextSelection) {
+        action.setEnabled(true);
+      } else if (fWindow.getActivePage() != null && fWindow.getActivePage().getActivePart() != null) {
+        //
+      }
+    }
+  }
+
+  public void run(IAction action) {
+    if (fEditor == null) {
+      IEditorPart targetEditor = fWindow.getActivePage().getActiveEditor();
+      if (targetEditor != null && (targetEditor instanceof PHPEditor)) {
+        fEditor = (PHPEditor) targetEditor;
+      }
+    }
+    if (fEditor != null) {
+      // determine the current Project from a (file-based) Editor
+      IFile f = ((IFileEditorInput) fEditor.getEditorInput()).getFile();
+      fProject = f.getProject();
+//      System.out.println(fProject.toString());
+
+      ITextSelection selection = (ITextSelection) fEditor.getSelectionProvider().getSelection();
+      IDocument doc = fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput());
+      int pos = selection.getOffset();
+      String word = getPHPIdentifier(doc, pos);
+      //      System.out.println(word);
+      if (word!=null && ! word.equals("")) {
+                               IdentifierIndexManager indexManager = PHPeclipsePlugin.getDefault().getIndexManager(fProject);
+                               List list = indexManager.getLocations(word);
+                               if (list!=null && list.size()>0) {
+                                       String workspaceLocation = PHPeclipsePlugin.getWorkspace().getRoot().getLocation().toString();
+                                       // TODO show all entries of the list in a dialog box
+                                       // at the moment allways the first entry will be opened
+                                       PHPIdentifierLocation location = (PHPIdentifierLocation)list.get(0);
+                                       String filename = workspaceLocation + location.getFilename();
+//                                     System.out.println(filename);
+                                       try {
+            PHPeclipsePlugin.getDefault().openFileInTextEditor(filename, 0, word);
+          } catch (CoreException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+          }
+                               }
+      }
+    }
+  }
+
+  public void setActiveEditor(IAction action, IEditorPart targetEditor) {
+    if (targetEditor != null && (targetEditor instanceof PHPEditor)) {
+      fEditor = (PHPEditor) targetEditor;
+    }
+  }
+
+  //  public static void openContextHelp(String word) {
+  //    IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
+  //    if (store.getBoolean(PHPHelpPlugin.PHP_CHM_ENABLED)) {
+  //      String[] arguments = { store.getString(PHPHelpPlugin.PHP_CHM_FILE), word };
+  //      MessageFormat form = new MessageFormat(store.getString(PHPHelpPlugin.PHP_CHM_COMMAND));
+  //      try {
+  //        Runtime runtime = Runtime.getRuntime();
+  //        String command = form.format(arguments);
+  //
+  //        runtime.exec(command);
+  //      } catch (IOException e) {
+  //      }
+  //    } else {
+  //      IHelp help = WorkbenchHelp.getHelpSupport();
+  //      if (help != null) {
+  //        PHPFunctionHelpResource helpResource = new PHPFunctionHelpResource(word);
+  //        WorkbenchHelp.getHelpSupport().displayHelpResource(helpResource);
+  //      } else {
+  //        //   showMessage(shell, dialogTitle, ActionMessages.getString("Open help not available"), false); //$NON-NLS-1$
+  //      }
+  //    }
+  //  }
+
+  private String getPHPIdentifier(IDocument doc, int pos) {
+    Point word = PHPWordExtractor.findWord(doc, pos);
+    if (word != null) {
+      try {
+        return doc.get(word.x, word.y);
+      } catch (BadLocationException e) {
+      }
+    }
+    return "";
+  }
+}
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/ExternalEditorInput.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/ExternalEditorInput.java
new file mode 100644 (file)
index 0000000..0b08b11
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ * Created on 06.09.2003
+ *
+ * To change the template for this generated file go to
+ * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
+ */
+package net.sourceforge.phpeclipse.builder;
+
+import org.eclipse.core.resources.IStorage;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.IEditorRegistry;
+import org.eclipse.ui.IPersistableElement;
+import org.eclipse.ui.IStorageEditorInput;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * An EditorInput for an external file.
+ */
+public class ExternalEditorInput implements IStorageEditorInput {
+
+        IStorage externalFile;
+
+        /**
+               * Two ExternalEditorInputs are equal if their IStorage's are equal.
+               * @see java.lang.Object#equals(java.lang.Object)
+               */
+        public boolean equals(Object obj) {
+                       if (this == obj)
+                                return true;
+                       if (!(obj instanceof ExternalEditorInput))
+                                return false;
+                       ExternalEditorInput other = (ExternalEditorInput) obj;
+                       return externalFile.equals(other.externalFile);
+        }
+
+        /*
+               * @see IEditorInput#exists()
+               */
+        public boolean exists() {
+                       // External file can not be deleted
+                       return true;
+        }
+
+        /*
+               * @see IAdaptable#getAdapter(Class)
+               */
+        public Object getAdapter(Class adapter) {
+                       return null;
+        }
+
+        /*
+               * @see IEditorInput#getContentType()
+               */
+        public String getContentType() {
+                       return externalFile.getFullPath().getFileExtension();
+        }
+
+        /*
+               * @see IEditorInput#getFullPath()
+               */
+        public String getFullPath() {
+                       return externalFile.getFullPath().toString();
+        }
+
+        /*
+               * @see IEditorInput#getImageDescriptor()
+               */
+        public ImageDescriptor getImageDescriptor() {
+                       IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry();
+                       return registry.getImageDescriptor(externalFile.getFullPath().getFileExtension());
+        }
+
+        /*
+               * @see IEditorInput#getName()
+               */
+        public String getName() {
+                       return externalFile.getName();
+        }
+
+        /*
+               * @see IEditorInput#getPersistable()
+               */
+        public IPersistableElement getPersistable() {
+                       return null;
+        }
+
+        /*
+               * see IStorageEditorInput#getStorage()
+               */
+        public IStorage getStorage() {
+                       return externalFile;
+        }
+
+        /*
+               * @see IEditorInput#getToolTipText()
+               */
+        public String getToolTipText() {
+                       return externalFile.getFullPath().toString();
+        }
+
+        public ExternalEditorInput(IStorage exFile) {
+                       externalFile = exFile;
+        }
+}
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/ExternalStorageDocumentProvider.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/ExternalStorageDocumentProvider.java
new file mode 100644 (file)
index 0000000..ea8aae0
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Created on 06.09.2003
+ *
+ */
+package net.sourceforge.phpeclipse.builder;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.ui.editors.text.StorageDocumentProvider;
+
+/**
+ * @author ed
+ * @version 1.0, May 19, 2003
+ */
+public class ExternalStorageDocumentProvider extends StorageDocumentProvider {
+
+        /* (non-Javadoc)
+               * @see org.eclipse.ui.texteditor.AbstractDocumentProvider#doSaveDocument(org.eclipse.core.runtime.IProgressMonitor, java.lang.Object, org.eclipse.jface.text.IDocument, boolean)
+               */
+        protected void doSaveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite)
+                       throws CoreException {
+                       if (element instanceof ExternalEditorInput) {
+                                ExternalEditorInput external = (ExternalEditorInput) element;
+                                FileStorage storage = (FileStorage)external.getStorage();
+                                String encoding = getEncoding(element);
+                                if (encoding == null)
+                                               encoding = getDefaultEncoding();
+                                try {
+                                               InputStream stream = new ByteArrayInputStream(document.get().getBytes(encoding));
+                                               try {
+                                                        // inform about the upcoming content change
+                                                        fireElementStateChanging(element);
+                                                        storage.setContents(stream, overwrite, true, monitor);
+                                               } catch (RuntimeException e) {
+                                                        // inform about failure
+                                                        fireElementStateChangeFailed(element);
+                                                        throw e;
+                                               }
+                                } catch (IOException e) {
+                                               IStatus s = new Status(IStatus.ERROR, PHPeclipsePlugin.PLUGIN_ID, IStatus.OK, e.getMessage(), e);
+                                               throw new CoreException(s);
+                                }
+
+                       } else {
+                                super.doSaveDocument(monitor, element, document, overwrite);
+                       }
+        }
+
+}
+
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/FileStorage.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/FileStorage.java
new file mode 100644 (file)
index 0000000..1080cd9
--- /dev/null
@@ -0,0 +1,125 @@
+/*
+ * Created on 06.09.2003
+ *
+ * To change the template for this generated file go to
+ * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
+ */
+package net.sourceforge.phpeclipse.builder;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import net.sourceforge.phpdt.internal.ui.util.StreamUtil;
+import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+
+import org.eclipse.core.resources.IStorage;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.PlatformObject;
+import org.eclipse.core.runtime.Status;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+/**
+ *
+ * @see IStorage
+ */
+public class FileStorage extends PlatformObject implements IStorage {
+        private boolean forceReadOnly;
+        private final IPath path;
+        private final File file;
+
+        /**
+               * Two FileStorages are equal if their IPaths are equal.
+               * @see java.lang.Object#equals(java.lang.Object)
+               */
+        public boolean equals(Object obj) {
+                       if (this == obj)
+                                return true;
+                       if (!(obj instanceof FileStorage))
+                                return false;
+                       FileStorage other = (FileStorage) obj;
+                       return path.equals(other.path);
+        }
+
+        /* (non-Javadoc)
+               * @see org.eclipse.core.resources.IStorage#getContents()
+               */
+        public InputStream getContents() throws CoreException {
+                       try {
+                                return new FileInputStream(file);
+                       } catch (FileNotFoundException e) {
+                                throw new CoreException(new Status(IStatus.ERROR, PHPeclipsePlugin.PLUGIN_ID, IStatus.ERROR, e.toString(), e));
+                       }
+        }
+
+        /* (non-Javadoc)
+               * @see org.eclipse.core.resources.IStorage#getFullPath()
+               */
+        public IPath getFullPath() {
+                       return this.path;
+        }
+
+        /* (non-Javadoc)
+               * @see org.eclipse.core.resources.IStorage#getName()
+               */
+        public String getName() {
+                       return this.path.lastSegment();
+        }
+
+        /* (non-Javadoc)
+               * @see org.eclipse.core.resources.IStorage#isReadOnly()
+               */
+        public boolean isReadOnly() {
+                       return forceReadOnly || !file.canWrite();
+        }
+
+        /**
+               * Method FileStorage.
+               * @param path
+               */
+        public FileStorage(IPath path) {
+                       this.path = path;
+                       this.file = path.toFile();
+        }
+
+        /* (non-Javadoc)
+               * @see java.lang.Object#toString()
+               */
+        public String toString() {
+                       return path.toOSString();
+        }
+
+        /**
+               * @param stream
+               * @param overwrite
+               * @param b
+               * @param monitor
+               */
+        public void setContents(InputStream stream, boolean overwrite, boolean b, IProgressMonitor monitor) throws CoreException {
+                       try {
+                               StreamUtil.transferStreams(stream, new FileOutputStream(file));
+                       } catch (FileNotFoundException e) {
+                                throw new CoreException(new Status(IStatus.ERROR, PHPeclipsePlugin.PLUGIN_ID, IStatus.ERROR, e.toString(), e));
+                       } catch (IOException e) {
+                                throw new CoreException(new Status(IStatus.ERROR, PHPeclipsePlugin.PLUGIN_ID, IStatus.ERROR, e.toString(), e));
+                       }
+        }
+
+        /**
+               * Some document providers (notably CompilationUnitDocumentProvider)
+               * can't handle read/write storage.
+               */
+        public void setReadOnly() {
+                       forceReadOnly = true;
+        }
+}
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/IdentifierIndexManager.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/IdentifierIndexManager.java
new file mode 100644 (file)
index 0000000..dd2672b
--- /dev/null
@@ -0,0 +1,446 @@
+package net.sourceforge.phpeclipse.builder;
+
+import java.io.BufferedReader;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
+import net.sourceforge.phpdt.core.compiler.InvalidInputException;
+import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
+import net.sourceforge.phpdt.internal.compiler.parser.SyntaxError;
+import net.sourceforge.phpeclipse.mover.obfuscator.PHPIdentifier;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+
+/**
+ * Manages the identifer index information for a specific project
+ *
+ */
+public class IdentifierIndexManager {
+
+  public class LineCreator implements ITerminalSymbols {
+
+    private Scanner fScanner;
+    private int fToken;
+
+    public LineCreator() {
+      fScanner = new Scanner(false, false);
+    }
+    /**
+     * gets the next token from input
+     */
+    private void getNextToken() {
+
+      try {
+        fToken = fScanner.getNextToken();
+        if (Scanner.DEBUG) {
+          int currentEndPosition = fScanner.getCurrentTokenEndPosition();
+          int currentStartPosition = fScanner.getCurrentTokenStartPosition();
+
+          System.out.print(currentStartPosition + "," + currentEndPosition + ": ");
+          System.out.println(fScanner.toStringAction(fToken));
+        }
+        return;
+      } catch (InvalidInputException e) {
+        // ignore errors
+      }
+      fToken = TokenNameERROR;
+    }
+
+    private void parseDeclarations(StringBuffer buf, boolean goBack) {
+      char[] ident;
+      int counter = 0;
+
+      try {
+        while (fToken != TokenNameEOF && fToken != TokenNameERROR) {
+          if (fToken == TokenNamevar) {
+            getNextToken();
+            if (fToken == TokenNameVariable) {
+              ident = fScanner.getCurrentIdentifierSource();
+              buf.append("\tv");
+              buf.append(ident);
+
+              getNextToken();
+            }
+          } else if (fToken == TokenNamefunction) {
+            getNextToken();
+            if (fToken == TokenNameAND) {
+              getNextToken();
+            }
+            if (fToken == TokenNameIdentifier) {
+              ident = fScanner.getCurrentIdentifierSource();
+              buf.append("\tm");
+              buf.append(ident);
+              getNextToken();
+              parseDeclarations(buf, true);
+            }
+          } else if (fToken == TokenNameclass) {
+            getNextToken();
+            if (fToken == TokenNameIdentifier) {
+              ident = fScanner.getCurrentIdentifierSource();
+              buf.append("\tc");
+              buf.append(ident);
+              getNextToken();
+
+              //skip tokens for classname, extends and others until we have the opening '{'
+              while (fToken != TokenNameLBRACE && fToken != TokenNameEOF && fToken != TokenNameERROR) {
+                getNextToken();
+              }
+              parseDeclarations(buf, true);
+            }
+          } else if ((fToken == TokenNameLBRACE) || (fToken == TokenNameDOLLAR_LBRACE)) {
+            getNextToken();
+            counter++;
+          } else if (fToken == TokenNameRBRACE) {
+            getNextToken();
+            --counter;
+            if (counter == 0 && goBack) {
+              return;
+            }
+          } else {
+            getNextToken();
+          }
+        }
+      } catch (SyntaxError e) {
+        // TODO Auto-generated catch block
+        e.printStackTrace();
+      }
+    }
+
+    public void parseIdentifiers(char[] charArray, StringBuffer buf) {
+      char[] ident;
+      String identifier;
+      int counter = 0;
+
+      fScanner.setSource(charArray);
+      fScanner.setPHPMode(false);
+      fToken = TokenNameEOF;
+      getNextToken();
+
+      try {
+        while (fToken != TokenNameEOF && fToken != TokenNameERROR) {
+          if (fToken == TokenNamefunction) {
+            getNextToken();
+            if (fToken == TokenNameAND) {
+              getNextToken();
+            }
+            if (fToken == TokenNameIdentifier) {
+              ident = fScanner.getCurrentIdentifierSource();
+              buf.append("\tf");
+              buf.append(ident);
+              getNextToken();
+              parseDeclarations(buf, true);
+            }
+          } else if (fToken == TokenNameclass) {
+            getNextToken();
+            if (fToken == TokenNameIdentifier) {
+              ident = fScanner.getCurrentIdentifierSource();
+              buf.append("\tc");
+              buf.append(ident);
+              getNextToken();
+
+              //skip fTokens for classname, extends and others until we have the opening '{'
+              while (fToken != TokenNameLBRACE && fToken != TokenNameEOF && fToken != TokenNameERROR) {
+                getNextToken();
+              }
+
+              parseDeclarations(buf, true);
+
+            }
+          } else {
+            getNextToken();
+          }
+        }
+      } catch (SyntaxError e) {
+        // TODO Auto-generated catch block
+        e.printStackTrace();
+      }
+    }
+  }
+
+  private HashMap fFileMap;
+  private String fFilename;
+  private HashMap fIndentifierMap;
+
+  public IdentifierIndexManager(String filename) {
+    fFilename = filename;
+    initialize();
+    readFile();
+  }
+
+  /**
+   * Add the information for a given IFile resource
+   *
+   */
+  public void addFile(IFile fileToParse) {
+    InputStream iStream;
+    LineCreator lineCreator = new LineCreator();
+    try {
+      iStream = fileToParse.getContents();
+
+      StringBuffer buf = new StringBuffer();
+      int c0;
+      try {
+        while ((c0 = iStream.read()) != (-1)) {
+          buf.append((char) c0);
+        }
+      } catch (IOException e) {
+        return;
+      }
+
+      StringBuffer lineBuffer = new StringBuffer();
+      //      lineBuffer.append(fileToParse.getLocation().toString());
+      lineBuffer.append(fileToParse.getFullPath().toString());
+      int lineLength = lineBuffer.length();
+      lineCreator.parseIdentifiers(buf.toString().toCharArray(), lineBuffer);
+      if (lineLength != lineBuffer.length()) {
+        addLine(lineBuffer.toString());
+      }
+    } catch (CoreException e1) {
+      // TODO Auto-generated catch block
+      e1.printStackTrace();
+    }
+  }
+
+  /**
+   * Adds a line of the index file for function, class, class-method and class-variable names
+   * 
+   * @param line
+   */
+  private void addLine(String line) {
+    StringTokenizer tokenizer;
+    String phpFileName = null;
+    String token;
+    String identifier = null;
+    String classname = null;
+    PHPIdentifier phpIdentifier = null;
+    boolean tokenExists = false;
+
+    tokenizer = new StringTokenizer(line, "\t");
+    // first token contains the filename:
+    if (tokenizer.hasMoreTokens()) {
+      phpFileName = tokenizer.nextToken();
+      //System.out.println(token);
+    } else {
+      return;
+    }
+    // all the other tokens are identifiers:
+    while (tokenizer.hasMoreTokens()) {
+      token = tokenizer.nextToken();
+      //System.out.println(token);
+      switch (token.charAt(0)) {
+        case 'c' : // class name
+          identifier = token.substring(1);
+          classname = identifier;
+          phpIdentifier = new PHPIdentifierLocation(identifier, PHPIdentifier.CLASS, phpFileName);
+          break;
+        case 'f' : // function name
+          identifier = token.substring(1);
+          phpIdentifier = new PHPIdentifierLocation(identifier, PHPIdentifier.FUNCTION, phpFileName);
+          break;
+        case 'm' : //method inside a class
+          identifier = token.substring(1);
+          phpIdentifier = new PHPIdentifierLocation(identifier, PHPIdentifier.METHOD, phpFileName, classname);
+          break;
+        case 'v' : // variable inside a class
+          identifier = token.substring(1);
+          phpIdentifier = new PHPIdentifierLocation(identifier, PHPIdentifier.VARIABLE, phpFileName, classname);
+          break;
+        default :
+          identifier = null;
+          phpIdentifier = null;
+          classname = null;
+      }
+      if (identifier != null && phpIdentifier != null) {
+        tokenExists = true;
+        ArrayList list = (ArrayList) fIndentifierMap.get(identifier);
+        if (list == null) {
+          list = new ArrayList();
+          list.add(phpIdentifier);
+          fIndentifierMap.put(identifier, list);
+        } else {
+          boolean flag = false;
+          for (int i = 0; i < list.size(); i++) {
+            if (list.get(i).equals(phpIdentifier)) {
+              flag = true;
+              break;
+            }
+          }
+          if (flag == false) {
+            list.add(phpIdentifier);
+          }
+        }
+      }
+    }
+    if (tokenExists) {
+      fFileMap.put(phpFileName, line);
+    }
+  }
+
+  /**
+   * Change the information for a given IFile resource
+   *
+   */
+  public void changeFile(IFile fileToParse) {
+    removeFile(fileToParse);
+    addFile(fileToParse);
+  }
+
+  /**
+   * Get a list of all PHPIdentifierLocation object's associated with an identifier
+   * 
+   * @param identifier
+   * @return
+   */
+  public List getLocations(String identifier) {
+    return (List) fIndentifierMap.get(identifier);
+  }
+
+  /**
+   * Initialize (i.e. clear) the current index information
+   *
+   */
+  public void initialize() {
+    fIndentifierMap = new HashMap();
+    fFileMap = new HashMap();
+  }
+
+  private void readFile() {
+
+    FileReader fileReader;
+    try {
+      fileReader = new FileReader(fFilename);
+
+      BufferedReader bufferedReader = new BufferedReader(fileReader);
+
+      String line;
+      while (bufferedReader.ready()) {
+        // all entries for one file are in a line
+        // separated by tabs !
+        line = bufferedReader.readLine();
+        addLine(line);
+      }
+
+      fileReader.close();
+    } catch (FileNotFoundException e) {
+      // ignore this
+      // TODO DialogBox which asks the user if she/he likes to build new index?
+    } catch (IOException e) {
+      // TODO Auto-generated catch block
+      e.printStackTrace();
+    }
+
+  }
+
+  /**
+   * Remove the information for a given IFile resource
+   *
+   */
+  public void removeFile(IFile fileToParse) {
+    //    String line = (String) fFileMap.get(fileToParse.getLocation().toString());
+    String line = (String) fFileMap.get(fileToParse.getFullPath().toString());
+    if (line != null) {
+      removeLine(line);
+    }
+  }
+
+  /**
+   * Removes a line of the index file for function, class, class-method and class-variable names
+   * 
+   * @param line
+   */
+  private void removeLine(String line) {
+    StringTokenizer tokenizer;
+    String phpFileName = null;
+    String token;
+    String identifier = null;
+    String classname = null;
+    PHPIdentifier phpIdentifier = null;
+    boolean tokenExists = false;
+
+    tokenizer = new StringTokenizer(line, "\t");
+    // first token contains the filename:
+    if (tokenizer.hasMoreTokens()) {
+      phpFileName = tokenizer.nextToken();
+      //System.out.println(token);
+    } else {
+      return;
+    }
+    // all the other tokens are identifiers:
+    while (tokenizer.hasMoreTokens()) {
+      token = tokenizer.nextToken();
+      //System.out.println(token);
+      switch (token.charAt(0)) {
+        case 'c' : // class name
+          identifier = token.substring(1);
+          classname = identifier;
+          phpIdentifier = new PHPIdentifierLocation(identifier, PHPIdentifier.CLASS, phpFileName);
+          break;
+        case 'f' : // function name
+          identifier = token.substring(1);
+          phpIdentifier = new PHPIdentifierLocation(identifier, PHPIdentifier.FUNCTION, phpFileName);
+          break;
+        case 'm' : //method inside a class
+          identifier = token.substring(1);
+          phpIdentifier = new PHPIdentifierLocation(identifier, PHPIdentifier.METHOD, phpFileName, classname);
+          break;
+        case 'v' : // variable inside a class
+          identifier = token.substring(1);
+          phpIdentifier = new PHPIdentifierLocation(identifier, PHPIdentifier.VARIABLE, phpFileName, classname);
+          break;
+        default :
+          identifier = null;
+          phpIdentifier = null;
+          classname = null;
+      }
+      if (identifier != null && phpIdentifier != null) {
+        ArrayList list = (ArrayList) fIndentifierMap.get(identifier);
+        if (list == null) {
+        } else {
+          for (int i = 0; i < list.size(); i++) {
+            if (list.get(i).equals(phpIdentifier)) {
+              list.remove(i);
+              break;
+            }
+          }
+          if (list.size() == 0) {
+            fIndentifierMap.remove(identifier);
+          }
+        }
+      }
+    }
+    fFileMap.remove(phpFileName);
+  }
+
+  /**
+   * Save the current index information in the projects index file
+   *
+   */
+  public void writeFile() {
+    FileWriter fileWriter;
+    try {
+      fileWriter = new FileWriter(fFilename);
+      String line;
+      Collection collection = fFileMap.values();
+      Iterator iterator = collection.iterator();
+      while (iterator.hasNext()) {
+        line = (String) iterator.next();
+        fileWriter.write(line + '\n');
+      }
+      fileWriter.close();
+    } catch (IOException e) {
+      // TODO Auto-generated catch block
+      e.printStackTrace();
+    }
+  }
+}
\ No newline at end of file
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/PHPIdentifierLocation.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/PHPIdentifierLocation.java
new file mode 100644 (file)
index 0000000..f3fb463
--- /dev/null
@@ -0,0 +1,60 @@
+package net.sourceforge.phpeclipse.builder;
+
+import net.sourceforge.phpeclipse.mover.obfuscator.PHPIdentifier;
+
+/**
+ * @author khartlage
+ *
+ */
+public class PHPIdentifierLocation extends PHPIdentifier {
+  private String fClassname;
+  private String fFilename;
+
+  public PHPIdentifierLocation(String identifier, int type, String filename) {
+    this(identifier, type, filename, null);
+  }
+
+       public PHPIdentifierLocation(String identifier, int type, String filename, String classname) {
+               super(identifier, type);
+               fFilename = filename;
+               fClassname = classname;
+       }
+  /* (non-Javadoc)
+   * @see java.lang.Object#equals(java.lang.Object)
+   */
+  public boolean equals(Object obj) {
+               if (!(obj instanceof PHPIdentifierLocation)) {
+                       return false;
+               }
+    return super.equals(obj)&&fFilename.equals(((PHPIdentifierLocation)obj).fFilename);
+  }
+
+  /**
+   * @return
+   */
+  public String getClassname() {
+    return fClassname;
+  }
+
+  /**
+   * @return
+   */
+  public String getFilename() {
+    return fFilename;
+  }
+
+  /**
+   * @param string
+   */
+  public void setClassname(String string) {
+    fClassname = string;
+  }
+
+  /**
+   * @param string
+   */
+  public void setFilename(String string) {
+    fFilename = string;
+  }
+
+}
index 4b9babe..4fd5108 100644 (file)
@@ -1,9 +1,12 @@
 package net.sourceforge.phpeclipse.builder;
 
+import java.io.File;
 import java.util.Map;
 
 import net.sourceforge.phpdt.internal.ui.util.PHPFileUtil;
+import net.sourceforge.phpeclipse.PHPeclipsePlugin;
 import net.sourceforge.phpeclipse.phpeditor.PHPParserAction;
+import net.sourceforge.phpeclipse.resourcesview.PHPProject;
 
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
@@ -35,8 +38,7 @@ public class ParserBuilder extends IncrementalProjectBuilder {
   /**
    * 
    */
-  protected IProject[] build(int kind, Map args, IProgressMonitor monitor)
-    throws CoreException {
+  protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
     monitor.beginTask("Parsing files", TOTAL_WORK);
 
     if (kind == IncrementalProjectBuilder.FULL_BUILD) {
@@ -48,7 +50,7 @@ public class ParserBuilder extends IncrementalProjectBuilder {
 
       IResourceDelta delta = getDelta(getProject());
       if (delta != null) {
-        delta.accept(new ParserVisitor(monitor));
+        delta.accept(new ParserVisitor(getProject(), monitor));
       }
 
     }
@@ -62,8 +64,8 @@ public class ParserBuilder extends IncrementalProjectBuilder {
    * 
    * @param iProject
    */
-  public void processFull(IProject iProject, final IProgressMonitor monitor) {
-
+  public void processFull(final IProject iProject, final IProgressMonitor monitor) {
+               final IdentifierIndexManager indexManager = PHPeclipsePlugin.getDefault().getIndexManager(iProject);
     // Create resource visitor logic
     IResourceVisitor myVisitor = new IResourceVisitor() {
       public boolean visit(IResource resource) throws CoreException {
@@ -71,11 +73,14 @@ public class ParserBuilder extends IncrementalProjectBuilder {
           if (monitor.isCanceled()) {
             throw new OperationCanceledException();
           }
-          if ((resource.getFileExtension() != null)
-            && PHPFileUtil.isPHPFile((IFile) resource)) {
+          if ((resource.getFileExtension() != null) && PHPFileUtil.isPHPFile((IFile) resource)) {
             monitor.worked(1);
             monitor.subTask("Parsing: " + resource.getFullPath());
+            // check for parsing errors
             PHPParserAction.parseFile((IFile) resource);
+            // update indexfile for the project:
+            PHPProject nature = (PHPProject) iProject.getNature(PHPeclipsePlugin.PHP_NATURE_ID);
+                                               indexManager.addFile((IFile) resource);
           }
         }
 
@@ -85,7 +90,14 @@ public class ParserBuilder extends IncrementalProjectBuilder {
 
     // Process the project using the visitor just created
     try {
+
+//      if (iProject.hasNature(PHPeclipsePlugin.PHP_NATURE_ID)) {
+//        thePHPProject = new PHPProject();
+//        thePHPProject.setProject(iProject);
+//      }
+                       indexManager.initialize();
       iProject.accept(myVisitor);
+                       indexManager.writeFile();
     } catch (CoreException e) {
       e.printStackTrace();
     }
@@ -120,11 +132,7 @@ public class ParserBuilder extends IncrementalProjectBuilder {
    * </pre>
    * </p>
    */
-  public void setInitializationData(
-    IConfigurationElement config,
-    String propertyName,
-    Object data)
-    throws CoreException {
+  public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
     super.setInitializationData(config, propertyName, data);
 
   }
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
   }
 
index bc7b049..a9c401d 100644 (file)
@@ -32,6 +32,7 @@ public class PHPAnalyzer extends DefaultMover implements ITerminalSymbols {
    * be synchronized
    */
   protected byte[] bytes = new byte[1024];
+  
   /**
    * Creates a PHPAnalyzer
    * @param console reports error to the PHPConsole
index a097a2e..5c59457 100644 (file)
@@ -3,20 +3,17 @@ package net.sourceforge.phpeclipse.mover.obfuscator;
 /**
  * @author khartlage
  *
- * To change this generated comment edit the template variable "typecomment":
- * Window>Preferences>Java>ObfuscatorIgnores.
- * To enable and disable the creation of type comments go to
- * Window>Preferences>Java>Code Generation.
  */
 public class PHPIdentifier {
-  
+
   public final static int CLASS = 1;
   public final static int FUNCTION = 2;
   public final static int VARIABLE = 3;
-  
+       public final static int METHOD = 4;
+
   private int fType;
   private String fIdentifier;
-  
+
   public PHPIdentifier(String identifier, int type) {
     fType = type;
     fIdentifier = identifier;
@@ -25,15 +22,15 @@ public class PHPIdentifier {
   public boolean isClass() {
     return fType == CLASS;
   }
-  
+
   public boolean isFuncton() {
     return fType == FUNCTION;
   }
-  
+
   public boolean isVariable() {
     return fType == VARIABLE;
   }
-  
+
   public void setType(int fType) {
     this.fType = fType;
   }
@@ -49,5 +46,16 @@ public class PHPIdentifier {
   public String getIdentifier() {
     return fIdentifier;
   }
-  
+
+  /* (non-Javadoc)
+   * @see java.lang.Object#equals(java.lang.Object)
+   */
+  public boolean equals(Object obj) {
+    if (!(obj instanceof PHPIdentifier)) {
+      return false;
+    }
+    return ((PHPIdentifier) obj).fType == fType && 
+           ((PHPIdentifier) obj).fIdentifier.equals(fIdentifier);
+  }
+
 }
index fbef0f3..f5cbca0 100644 (file)
@@ -58,53 +58,53 @@ public class PHPParserAction extends TextEditorAction {
    */
   public void run() {
     boolean phpFlag = false;
-               
-  //  try {
-      fileToParse = getPHPFile();
-                       parseFile(fileToParse);
+
+    //  try {
+    fileToParse = getPHPFile();
+    parseFile(fileToParse);
   }
 
-       public static void parseFile(IFile fileToParse) {
-                       boolean phpFlag = false;
-                       try {
-                               
-                               if (fileToParse == null) {
-                                       // should never happen
-                                       System.err.println("Error : no file in the editor");
-                                       // should throw an exception
-                                       return;
-                               }
-                               String name = fileToParse.getName().toLowerCase();
-                               for (int i = 0; i<EXTENSIONS.length; i++) {
-                                       if (name.endsWith(EXTENSIONS[i])) {
-                                               phpFlag = true;  // php file extension
-                                               break;
-                                       }
-                               }
-                               if (phpFlag) {
-                                       IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
-                                       if (store.getString(PHPeclipsePlugin.PHP_PARSER_DEFAULT).equals(PHPeclipsePlugin.PHP_INTERNAL_PARSER)) {
-                                               // first delete all the previous markers
-                                               fileToParse.deleteMarkers(IMarker.PROBLEM, false, 0);
-
-                                               //the tasks are removed here
-                                               fileToParse.deleteMarkers(IMarker.TASK, false, 0);
-
-                                               try {
-                                                       InputStream iStream = fileToParse.getContents();
-                                                       //        int c = iStream.read();
-                                                       parse(fileToParse,iStream);
-                                                       iStream.close();
-                                               } catch (IOException e) {
-                                               }
-                                       } else {
-                                               PHPParserSuperclass.phpExternalParse(fileToParse);
-                                       }
-                               }
-                       } catch (CoreException e) {
-                       }
-
-               }
+  public static void parseFile(IFile fileToParse) {
+    boolean phpFlag = false;
+    try {
+
+      if (fileToParse == null) {
+        // should never happen
+        System.err.println("Error : no file in the editor");
+        // should throw an exception
+        return;
+      }
+      String name = fileToParse.getName().toLowerCase();
+      for (int i = 0; i < EXTENSIONS.length; i++) {
+        if (name.endsWith(EXTENSIONS[i])) {
+          phpFlag = true; // php file extension
+          break;
+        }
+      }
+      if (phpFlag) {
+        IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
+        if (store.getString(PHPeclipsePlugin.PHP_PARSER_DEFAULT).equals(PHPeclipsePlugin.PHP_INTERNAL_PARSER)) {
+          // first delete all the previous markers
+          fileToParse.deleteMarkers(IMarker.PROBLEM, false, 0);
+
+          //the tasks are removed here
+          fileToParse.deleteMarkers(IMarker.TASK, false, 0);
+
+          try {
+            InputStream iStream = fileToParse.getContents();
+            //        int c = iStream.read();
+            parse(fileToParse, iStream);
+            iStream.close();
+          } catch (IOException e) {
+          }
+        } else {
+          PHPParserSuperclass.phpExternalParse(fileToParse);
+        }
+      }
+    } catch (CoreException e) {
+    }
+
+  }
   /**
    * Finds the file that's currently opened in the PHP Text Editor
    */
index 70e5200..59d4030 100644 (file)
@@ -8,7 +8,6 @@ import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.jface.dialogs.ErrorDialog;
-import org.eclipse.jface.preference.DirectoryFieldEditor;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
index 775c6d7..e42cf0a 100644 (file)
@@ -29,12 +29,20 @@ import org.xml.sax.XMLReader;
 
 public class PHPProject implements IProjectNature, PHPElement {
   protected IProject fProject;
-  protected List loadPathEntries;
-  protected boolean scratched;
+ // protected IndexFileReader fIndexManager;
+  protected List fLoadPathEntries;
+  protected boolean fScratched;
 
   public PHPProject() {
   }
 
+  public void addLoadPathEntry(IProject anotherPHPProject) {
+    fScratched = true;
+
+    LoadPathEntry newEntry = new LoadPathEntry(anotherPHPProject);
+    getLoadPathEntries().add(newEntry);
+  }
+
   public void configure() throws CoreException {
     // get project description and then the associated build commands 
     IProjectDescription desc = fProject.getDescription();
@@ -66,96 +74,32 @@ public class PHPProject implements IProjectNature, PHPElement {
   public void deconfigure() throws CoreException {
   }
 
-  public IProject getProject() {
-    return fProject;
-  }
-
-  protected IProject getProject(String name) {
-    return PHPeclipsePlugin.getWorkspace().getRoot().getProject(name);
-  }
-
-  public void setProject(IProject aProject) {
-    fProject = aProject;
-  }
-
-  public void addLoadPathEntry(IProject anotherPHPProject) {
-    scratched = true;
-
-    LoadPathEntry newEntry = new LoadPathEntry(anotherPHPProject);
-    getLoadPathEntries().add(newEntry);
-  }
-
-  public void removeLoadPathEntry(IProject anotherPHPProject) {
-    Iterator entries = getLoadPathEntries().iterator();
-    while (entries.hasNext()) {
-      LoadPathEntry entry = (LoadPathEntry) entries.next();
-      if (entry.getType() == LoadPathEntry.TYPE_PROJECT
-        && entry.getProject().getName().equals(anotherPHPProject.getName())) {
-        getLoadPathEntries().remove(entry);
-        scratched = true;
-        break;
-      }
-    }
-  }
-
   public List getLoadPathEntries() {
-    if (loadPathEntries == null) {
+    if (fLoadPathEntries == null) {
       loadLoadPathEntries();
     }
 
-    return loadPathEntries;
-  }
-
-  public List getReferencedProjects() {
-    List referencedProjects = new ArrayList();
-
-    Iterator iterator = getLoadPathEntries().iterator();
-    while (iterator.hasNext()) {
-      LoadPathEntry pathEntry = (LoadPathEntry) iterator.next();
-      if (pathEntry.getType() == LoadPathEntry.TYPE_PROJECT)
-        referencedProjects.add(pathEntry.getProject());
-    }
-
-    return referencedProjects;
-  }
-
-  protected void loadLoadPathEntries() {
-    loadPathEntries = new ArrayList();
-
-    IFile loadPathsFile = getLoadPathEntriesFile();
-
-    XMLReader reader = null;
-    try {
-      reader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
-      reader.setContentHandler(getLoadPathEntriesContentHandler());
-      reader.parse(new InputSource(loadPathsFile.getContents()));
-    } catch (Exception e) {
-      //the file is nonextant or unreadable
-    }
+    return fLoadPathEntries;
   }
 
   protected ContentHandler getLoadPathEntriesContentHandler() {
     return new ContentHandler() {
-      public void characters(char[] arg0, int arg1, int arg2)
-        throws SAXException {
+      public void characters(char[] arg0, int arg1, int arg2) throws SAXException {
       }
 
       public void endDocument() throws SAXException {
       }
 
-      public void endElement(String arg0, String arg1, String arg2)
-        throws SAXException {
+      public void endElement(String arg0, String arg1, String arg2) throws SAXException {
       }
 
       public void endPrefixMapping(String arg0) throws SAXException {
       }
 
-      public void ignorableWhitespace(char[] arg0, int arg1, int arg2)
-        throws SAXException {
+      public void ignorableWhitespace(char[] arg0, int arg1, int arg2) throws SAXException {
       }
 
-      public void processingInstruction(String arg0, String arg1)
-        throws SAXException {
+      public void processingInstruction(String arg0, String arg1) throws SAXException {
       }
 
       public void setDocumentLocator(Locator arg0) {
@@ -167,23 +111,16 @@ public class PHPProject implements IProjectNature, PHPElement {
       public void startDocument() throws SAXException {
       }
 
-      public void startElement(
-        String namespaceURI,
-        String localName,
-        String qName,
-        Attributes atts)
-        throws SAXException {
+      public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
         if ("pathentry".equals(qName))
           if ("project".equals(atts.getValue("type"))) {
             IPath referencedProjectPath = new Path(atts.getValue("path"));
-            IProject referencedProject =
-              getProject(referencedProjectPath.lastSegment());
-            loadPathEntries.add(new LoadPathEntry(referencedProject));
+            IProject referencedProject = getProject(referencedProjectPath.lastSegment());
+            fLoadPathEntries.add(new LoadPathEntry(referencedProject));
           }
       }
 
-      public void startPrefixMapping(String arg0, String arg1)
-        throws SAXException {
+      public void startPrefixMapping(String arg0, String arg1) throws SAXException {
       }
     };
   }
@@ -192,25 +129,11 @@ public class PHPProject implements IProjectNature, PHPElement {
     return fProject.getFile(".loadpath");
   }
 
-  public void save() throws CoreException {
-    if (scratched) {
-      InputStream xmlPath =
-        new ByteArrayInputStream(getLoadPathXML().getBytes());
-      IFile loadPathsFile = getLoadPathEntriesFile();
-      if (!loadPathsFile.exists())
-        loadPathsFile.create(xmlPath, true, null);
-      else
-        loadPathsFile.setContents(xmlPath, true, false, null);
-
-      scratched = false;
-    }
-  }
-
   protected String getLoadPathXML() {
     StringBuffer buffer = new StringBuffer();
     buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><loadpath>");
 
-    Iterator pathEntriesIterator = loadPathEntries.iterator();
+    Iterator pathEntriesIterator = fLoadPathEntries.iterator();
 
     while (pathEntriesIterator.hasNext()) {
       LoadPathEntry entry = (LoadPathEntry) pathEntriesIterator.next();
@@ -221,8 +144,73 @@ public class PHPProject implements IProjectNature, PHPElement {
     return buffer.toString();
   }
 
+  public IProject getProject() {
+    return fProject;
+  }
+
+  protected IProject getProject(String name) {
+    return PHPeclipsePlugin.getWorkspace().getRoot().getProject(name);
+  }
+
+  public List getReferencedProjects() {
+    List referencedProjects = new ArrayList();
+
+    Iterator iterator = getLoadPathEntries().iterator();
+    while (iterator.hasNext()) {
+      LoadPathEntry pathEntry = (LoadPathEntry) iterator.next();
+      if (pathEntry.getType() == LoadPathEntry.TYPE_PROJECT)
+        referencedProjects.add(pathEntry.getProject());
+    }
+
+    return referencedProjects;
+  }
+
   public IResource getUnderlyingResource() {
     return fProject;
   }
 
+  protected void loadLoadPathEntries() {
+    fLoadPathEntries = new ArrayList();
+
+    IFile loadPathsFile = getLoadPathEntriesFile();
+
+    XMLReader reader = null;
+    try {
+      reader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
+      reader.setContentHandler(getLoadPathEntriesContentHandler());
+      reader.parse(new InputSource(loadPathsFile.getContents()));
+    } catch (Exception e) {
+      //the file is nonextant or unreadable
+    }
+  }
+
+  public void removeLoadPathEntry(IProject anotherPHPProject) {
+    Iterator entries = getLoadPathEntries().iterator();
+    while (entries.hasNext()) {
+      LoadPathEntry entry = (LoadPathEntry) entries.next();
+      if (entry.getType() == LoadPathEntry.TYPE_PROJECT && entry.getProject().getName().equals(anotherPHPProject.getName())) {
+        getLoadPathEntries().remove(entry);
+        fScratched = true;
+        break;
+      }
+    }
+  }
+
+  public void save() throws CoreException {
+    if (fScratched) {
+      InputStream xmlPath = new ByteArrayInputStream(getLoadPathXML().getBytes());
+      IFile loadPathsFile = getLoadPathEntriesFile();
+      if (!loadPathsFile.exists())
+        loadPathsFile.create(xmlPath, true, null);
+      else
+        loadPathsFile.setContents(xmlPath, true, false, null);
+
+      fScratched = false;
+    }
+  }
+
+  public void setProject(IProject aProject) {
+    fProject = aProject;
+  }
+
 }