Merged "Open PHP Declaration" and "Open Include File" into one action "Open Declarati...
authoraxelcl <axelcl>
Wed, 5 Jan 2005 21:18:59 +0000 (21:18 +0000)
committeraxelcl <axelcl>
Wed, 5 Jan 2005 21:18:59 +0000 (21:18 +0000)
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/util/PHPFileUtil.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPOpenDeclarationEditorAction.java

index fb2c252..abb27ea 100644 (file)
@@ -3406,7 +3406,7 @@ public class Parser //extends PHPParserSuperclass
               problemReporter.phpIncludeNotExistWarning(args, literal.sourceStart, literal.sourceEnd, referenceContext,
                   compilationUnit.compilationResult);
             } else {
-              impt.setFile( project.getFile(path) );
+              impt.setFile( PHPFileUtil.createFile(path, project) );
             }
           }
         }
index 9341058..432359c 100644 (file)
@@ -104,11 +104,28 @@ public class PHPFileUtil {
   }
 
   /**
-   * Determine the path of an include name string
+   * Creata the file for the given absolute file path 
+   * 
+   * @param absoluteFilePath
+   * @param project
+   * @return the file for the given absolute file path or <code>null</code> if no existing file can be found
+   */
+  public static IFile createFile(IPath absoluteFilePath, IProject project) {
+    if (absoluteFilePath == null || project == null) {
+      return null;
+    }
+    String projectPath = project.getLocation().toString();
+    String filePath = absoluteFilePath.toString().substring(projectPath.length() + 1);
+    return project.getFile(filePath);
+  }
+
+  /**
+   * Determine the path of an include name string  
    * 
    * @param includeNameString
    * @param resource
    * @param project
+   * @return the path for the given include filename or <code>null</code> if no existing file can be found
    */
   public static IPath determineFilePath(String includeNameString, IResource resource, IProject project) {
     IPath documentRootPath = ProjectPrefUtil.getDocumentRoot(project);
index 2dd8a72..486f7cf 100644 (file)
@@ -7,11 +7,11 @@
  **********************************************************************************************************************************/
 package net.sourceforge.phpeclipse.actions;
 
-import java.io.File;
 import java.util.Collections;
 import java.util.List;
 import java.util.Set;
 
+import net.sourceforge.phpdt.internal.ui.util.PHPFileUtil;
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
 import net.sourceforge.phpeclipse.builder.PHPIdentifierLocation;
@@ -21,8 +21,9 @@ import net.sourceforge.phpeclipse.phpeditor.php.PHPWordExtractor;
 import org.eclipse.core.resources.IContainer;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
+import org.eclipse.core.internal.resources.File;
 import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.IPath;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.text.BadLocationException;
 import org.eclipse.jface.text.IDocument;
@@ -102,10 +103,18 @@ public class PHPOpenDeclarationEditorAction extends ActionDelegate implements IE
   private void openIncludeFile(String filename) {
     if (filename != null && !filename.equals("")) {
       try {
-        IFile file = getIncludeFile(fProject, (IFileEditorInput) fEditor.getEditorInput(), filename);
-        if (file != null && file.exists()) {
-          PHPeclipsePlugin.getDefault().openFileInTextEditor(file.getLocation().toString());
-          return;
+        IFile currentFile = ((IFileEditorInput) fEditor.getEditorInput()).getFile();
+        IPath path = PHPFileUtil.determineFilePath(filename, currentFile, fProject);
+        if (path != null) { 
+//          String projectPath = fProject.getLocation().toString();
+//          String filePath = path.toString().substring(projectPath.length()+1);
+//          IFile file = fProject.getFile(filePath);
+          IFile file = PHPFileUtil.createFile(path, fProject);
+          //        IFile file = getIncludeFile(fProject, (IFileEditorInput) fEditor.getEditorInput(), filename);
+          if (file != null && file.exists()) {
+            PHPeclipsePlugin.getDefault().openFileInTextEditor(file.getLocation().toString());
+            return;
+          }
         }
       } catch (Exception e) {
         // ignore
@@ -118,7 +127,7 @@ public class PHPOpenDeclarationEditorAction extends ActionDelegate implements IE
         List list = indexManager.getFileList(filename);
         if (list != null && list.size() > 0) {
           //String workspaceLocation = PHPeclipsePlugin.getWorkspace().getRoot().getLocation().toString();
-          String workspaceLocation = fProject.getLocation().toString() + File.separatorChar;
+          String workspaceLocation = fProject.getLocation().toString() + java.io.File.separatorChar;
 
           ListSelectionDialog listSelectionDialog = new ListSelectionDialog(PHPeclipsePlugin.getDefault().getWorkbench()
               .getActiveWorkbenchWindow().getShell(), list, new ListContentProvider(), new LabelProvider(),
@@ -162,7 +171,7 @@ public class PHPOpenDeclarationEditorAction extends ActionDelegate implements IE
         //          String workspaceLocation = PHPeclipsePlugin.getWorkspace().getRoot()
         //              .getLocation().toString();
 
-        String workspaceLocation = fProject.getLocation().toString() + File.separatorChar;
+        String workspaceLocation = fProject.getLocation().toString() + java.io.File.separatorChar;
         // TODO show all entries of the list in a dialog box
         // at the moment always the first entry will be opened
         if (locationsList.size() > 1) {
@@ -306,28 +315,28 @@ public class PHPOpenDeclarationEditorAction extends ActionDelegate implements IE
     return editorInput.getFile().getParent();
   }
 
-  private IFile getIncludeFile(IProject project, IFileEditorInput editorInput, String relativeFilename) {
-    IContainer container = getWorkingLocation(editorInput);
-    String fullPath = project.getLocation().toString();
-    IFile file = null;
-    if (relativeFilename.startsWith("../")) {
-      Path path = new Path(relativeFilename);
-      file = container.getFile(path);
-      return file;
-    }
-    int index = relativeFilename.lastIndexOf('/');
-
-    if (index >= 0) {
-      Path path = new Path(relativeFilename);
-      file = project.getFile(path);
-      if (file.exists()) {
-        return file;
-      }
-    }
-
-    Path path = new Path(relativeFilename);
-    file = container.getFile(path);
-
-    return file;
-  }
+  //  private IFile getIncludeFile(IProject project, IFileEditorInput editorInput, String relativeFilename) {
+  //    IContainer container = getWorkingLocation(editorInput);
+  //    String fullPath = project.getLocation().toString();
+  //    IFile file = null;
+  //    if (relativeFilename.startsWith("../")) {
+  //      Path path = new Path(relativeFilename);
+  //      file = container.getFile(path);
+  //      return file;
+  //    }
+  //    int index = relativeFilename.lastIndexOf('/');
+  //
+  //    if (index >= 0) {
+  //      Path path = new Path(relativeFilename);
+  //      file = project.getFile(path);
+  //      if (file.exists()) {
+  //        return file;
+  //      }
+  //    }
+  //
+  //    Path path = new Path(relativeFilename);
+  //    file = container.getFile(path);
+  //
+  //    return file;
+  //  }
 }
\ No newline at end of file