changes for added mapped path field
authorcperkonig <cperkonig>
Sun, 29 Feb 2004 18:35:13 +0000 (18:35 +0000)
committercperkonig <cperkonig>
Sun, 29 Feb 2004 18:35:13 +0000 (18:35 +0000)
net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/PHPSourceLocator.java

index c61f815..c00a9ad 100644 (file)
@@ -1,6 +1,7 @@
 package net.sourceforge.phpdt.internal.debug.ui;
 
 import java.util.Map;
+import java.util.Iterator;
 
 import net.sourceforge.phpdt.internal.debug.core.model.PHPStackFrame;
 import net.sourceforge.phpdt.internal.launching.PHPLaunchConfigurationAttribute;
@@ -29,9 +30,9 @@ import org.eclipse.ui.part.FileEditorInput;
 
 public class PHPSourceLocator implements IPersistableSourceLocator, ISourcePresentation {
   private String absoluteWorkingDirectory;
-  private Map fileMap = null;
+  private Map pathMap = null;
        private boolean remoteDebug;
-       private IPath remotePath;
+       private IPath remoteSourcePath;
        private String projectName;
 
   public PHPSourceLocator() {
@@ -60,13 +61,13 @@ public class PHPSourceLocator implements IPersistableSourceLocator, ISourcePrese
   public void initializeDefaults(ILaunchConfiguration configuration) throws CoreException {
     this.absoluteWorkingDirectory = configuration.getAttribute(PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, "");
                this.remoteDebug=configuration.getAttribute(PHPLaunchConfigurationAttribute.REMOTE_DEBUG,false);
-               this.fileMap = configuration.getAttribute(PHPLaunchConfigurationAttribute.FILE_MAP, (Map)null);
+               this.pathMap = configuration.getAttribute(PHPLaunchConfigurationAttribute.FILE_MAP, (Map)null);
                this.projectName =configuration.getAttribute(PHPLaunchConfigurationAttribute.PROJECT_NAME, "");
                
                if (BootLoader.getOS().equals(BootLoader.OS_WIN32))
-                       this.remotePath= new Path((configuration.getAttribute(PHPLaunchConfigurationAttribute.REMOTE_PATH, "")).toLowerCase());
+                       this.remoteSourcePath= new Path((configuration.getAttribute(PHPLaunchConfigurationAttribute.REMOTE_PATH, "")).toLowerCase());
                else
-                       this.remotePath= new Path(configuration.getAttribute(PHPLaunchConfigurationAttribute.REMOTE_PATH, ""));
+                       this.remoteSourcePath= new Path(configuration.getAttribute(PHPLaunchConfigurationAttribute.REMOTE_PATH, ""));
                
 //             system.os.name
 
@@ -77,29 +78,38 @@ public class PHPSourceLocator implements IPersistableSourceLocator, ISourcePrese
    */
   public Object getSourceElement(IStackFrame stackFrame) {
   
-               String key=((PHPStackFrame) stackFrame).getFileName();
-
-               
+               String fileName=((PHPStackFrame) stackFrame).getFileName();
                String file="";
                    
     if (remoteDebug)
     {
-                       IPath path = new Path(key);
-                       if (remotePath.isPrefixOf(path))
+                       IPath path = new Path(fileName);
+                       if (remoteSourcePath.isPrefixOf(path))
                        {
                                IPath projectPath;
-                               path=path.removeFirstSegments(remotePath.matchingFirstSegments(path));
+                               path=path.removeFirstSegments(remoteSourcePath.matchingFirstSegments(path));
                                file=path.toString();
                                projectPath=(PHPeclipsePlugin.getWorkspace().getRoot().getProject(projectName).getLocation());
-                               file=(projectPath.append(path)).toString();                     
+                               return (projectPath.append(path)).toOSString();
                        }
-//     file=(String)(fileMap.get(key));
-    } else
-    {
-       file=key;
+   
+                       if (pathMap == null) {
+                               return fileName;
+                       }
+                       Iterator iterator = pathMap.keySet().iterator();
+                       while (iterator.hasNext()) {
+                               String local = (String) iterator.next();
+                               IPath remotePath = new Path((String) pathMap.get(local));
+                               if (remotePath.isPrefixOf(path)) {
+                                       path=path.removeFirstSegments(remotePath.matchingFirstSegments(path));
+                                       IPath localPath= new Path(local);
+                                       return localPath.append(path).toOSString();
+                               }
+                       }
+                       return fileName;
+               } else {                
+                       return fileName;
     }
-    
-    return file;
   }
 
   /**