Added support to open function from variables view
authorEugene Ostroukhov <eugeneo@symbian.org>
Tue, 08 Jun 2010 15:33:30 -0700
changeset 359 dceb3fa18927
parent 356 8e561bc07a21
child 360 c1c74d169148
Added support to open function from variables view
org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/WRTProjectWorkspaceBridge.java
org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/WebApplicationSourceLocator.java
--- a/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/WRTProjectWorkspaceBridge.java	Tue Jun 08 14:02:43 2010 -0700
+++ b/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/WRTProjectWorkspaceBridge.java	Tue Jun 08 15:33:30 2010 -0700
@@ -1,6 +1,5 @@
 package org.symbian.tools.wrttools.debug.internal.launch;
 
-import java.io.File;
 import java.util.ArrayList;
 import java.util.Collection;
 
@@ -8,14 +7,12 @@
 import org.chromium.debug.core.model.BreakpointSynchronizer.Direction;
 import org.chromium.debug.core.model.ChromiumLineBreakpoint;
 import org.chromium.debug.core.model.DebugTargetImpl;
-import org.chromium.debug.core.model.StackFrame;
 import org.chromium.debug.core.model.VmResource;
 import org.chromium.debug.core.model.WorkspaceBridge;
 import org.chromium.sdk.CallFrame;
 import org.chromium.sdk.JavascriptVm;
 import org.chromium.sdk.JavascriptVm.ScriptsCallback;
 import org.chromium.sdk.Script;
-import org.eclipse.core.filesystem.EFS;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IMarker;
 import org.eclipse.core.resources.IProject;
@@ -23,154 +20,124 @@
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.debug.core.DebugPlugin;
 import org.eclipse.debug.core.ILaunch;
-import org.eclipse.debug.core.model.ISourceLocator;
-import org.eclipse.debug.core.model.IStackFrame;
+import org.eclipse.debug.core.sourcelookup.ISourceContainer;
+import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector;
+import org.eclipse.debug.core.sourcelookup.containers.ProjectSourceContainer;
 import org.symbian.tools.wrttools.debug.internal.Activator;
 import org.symbian.tools.wrttools.debug.internal.model.ResourceManager;
 import org.symbian.tools.wrttools.debug.internal.model.WorkspaceBreakpointHandler;
-import org.symbian.tools.wrttools.previewer.PreviewerPlugin;
 
 public class WRTProjectWorkspaceBridge implements WorkspaceBridge {
-	public static final class Factory implements WorkspaceBridge.Factory {
-		private final IProject project;
+    public static final class Factory implements WorkspaceBridge.Factory {
+        private final IProject project;
 
-		public Factory(IProject project) {
-			this.project = project;
-		}
+        public Factory(IProject project) {
+            this.project = project;
+        }
 
-		public WorkspaceBridge attachedToVm(DebugTargetImpl debugTargetImpl,
-				JavascriptVm javascriptVm) {
-			return new WRTProjectWorkspaceBridge(debugTargetImpl, javascriptVm,
-					project);
-		}
+        public WorkspaceBridge attachedToVm(DebugTargetImpl debugTargetImpl, JavascriptVm javascriptVm) {
+            return new WRTProjectWorkspaceBridge(debugTargetImpl, javascriptVm, project);
+        }
 
-		public String getDebugModelIdentifier() {
-			return DEBUG_MODEL_ID;
-		}
+        public String getDebugModelIdentifier() {
+            return DEBUG_MODEL_ID;
+        }
 
-		public JsLabelProvider getLabelProvider() {
-			return new WrtLabelProvider();
-		}
+        public JsLabelProvider getLabelProvider() {
+            return new WrtLabelProvider();
+        }
+    }
 
-	}
-
-	public final static String DEBUG_MODEL_ID = "org.symbian.debug";
+    public final static String DEBUG_MODEL_ID = "org.symbian.debug";
 
-	private final BreakpointHandler breakpointHandler;
-	private final JavascriptVm javascriptVm;
-	private final IProject project;
-	private final ResourceManager resourceManager;
+    private final BreakpointHandler breakpointHandler;
+    private final JavascriptVm javascriptVm;
+    private final IProject project;
+    private final ResourceManager resourceManager;
 
-	public WRTProjectWorkspaceBridge(DebugTargetImpl debugTargetImpl,
-			JavascriptVm javascriptVm, IProject project) {
-		this.javascriptVm = javascriptVm;
-		this.project = project;
+    public WRTProjectWorkspaceBridge(DebugTargetImpl debugTargetImpl, JavascriptVm javascriptVm, IProject project) {
+        this.javascriptVm = javascriptVm;
+        this.project = project;
         this.resourceManager = new ResourceManager();
+        this.sourceLocator = new WebApplicationSourceLocator(resourceManager);
         breakpointHandler = new WorkspaceBreakpointHandler(debugTargetImpl, resourceManager);
-		ILaunch launch = debugTargetImpl.getLaunch();
-		launch.setSourceLocator(sourceLocator);
-	}
-
-	public void beforeDetach() {
-		// Do nothing
-	}
-
-	public BreakpointHandler getBreakpointHandler() {
-		return breakpointHandler;
-	}
-
-	public void handleVmResetEvent() {
-		resourceManager.clear();
-	}
+        ILaunch launch = debugTargetImpl.getLaunch();
+        try {
+            sourceLocator.initializeDefaults(launch.getLaunchConfiguration());
+            sourceLocator.setSourceContainers(new ISourceContainer[] { new ProjectSourceContainer(project, false) });
+        } catch (CoreException e) {
+            throw new RuntimeException(e);
+        }
+        launch.setSourceLocator(sourceLocator);
+    }
 
-	public void launchRemoved() {
-		// Do nothing
-	}
+    public void beforeDetach() {
+        // Do nothing
+    }
 
-	public void reloadScriptsAtStart() {
-		javascriptVm.getScripts(new ScriptsCallback() {
-			public void failure(String errorMessage) {
-				Activator.log(errorMessage);
-			}
+    public BreakpointHandler getBreakpointHandler() {
+        return breakpointHandler;
+    }
 
-			public void success(Collection<Script> scripts) {
-				if (!javascriptVm.isAttached()) {
-					return;
-				}
-				for (Script script : scripts) {
-					resourceManager.addScript(script);
-				}
+    public void handleVmResetEvent() {
+        resourceManager.clear();
+    }
 
-				IMarker[] markers;
-				try {
-					markers = project.findMarkers(
-							ChromiumLineBreakpoint.BREAKPOINT_MARKER, true,
-							IResource.DEPTH_INFINITE);
-					Collection<ChromiumLineBreakpoint> breakpoints = new ArrayList<ChromiumLineBreakpoint>(
-							markers.length);
-					for (IMarker marker : markers) {
-						// If it is not ChromiumLineBreakpoint -
-						// something's gone horribly wrong. Better get
-						// ClassCastException
-						ChromiumLineBreakpoint breakpoint = (ChromiumLineBreakpoint) DebugPlugin
-								.getDefault().getBreakpointManager()
-								.getBreakpoint(marker);
-						breakpointHandler.breakpointAdded(breakpoint);
-						breakpoints.add(breakpoint);
-					}
-				} catch (CoreException e) {
-					Activator.log(e);
-				}
+    public void launchRemoved() {
+        // Do nothing
+    }
 
-			}
-		});
-	}
+    public void reloadScriptsAtStart() {
+        javascriptVm.getScripts(new ScriptsCallback() {
+            public void failure(String errorMessage) {
+                Activator.log(errorMessage);
+            }
 
-	public void scriptLoaded(Script newScript) {
-		resourceManager.addScript(newScript);
-	}
+            public void success(Collection<Script> scripts) {
+                if (!javascriptVm.isAttached()) {
+                    return;
+                }
+                for (Script script : scripts) {
+                    resourceManager.addScript(script);
+                }
 
-	public int getLineNumber(CallFrame stackFrame) {
-		int offset = 0;
-		Script script = stackFrame.getScript();
-		if (script != null) {
-			offset = script.getStartLine();
-		}
-		return offset + stackFrame.getLineNumber() + 1;
-	}
-
-	/**
-	 * This very simple source locator works because we provide our own source
-	 * files. We'll have to try harder, once we link with resource js files.
-	 */
-	private final ISourceLocator sourceLocator = new ISourceLocator() {
-		public Object getSourceElement(IStackFrame stackFrame) {
-			if (stackFrame instanceof StackFrame == false) {
-				return null;
-			}
-			StackFrame jsStackFrame = (StackFrame) stackFrame;
+                IMarker[] markers;
+                try {
+                    markers = project.findMarkers(ChromiumLineBreakpoint.BREAKPOINT_MARKER, true,
+                            IResource.DEPTH_INFINITE);
+                    Collection<ChromiumLineBreakpoint> breakpoints = new ArrayList<ChromiumLineBreakpoint>(
+                            markers.length);
+                    for (IMarker marker : markers) {
+                        // If it is not ChromiumLineBreakpoint -
+                        // something's gone horribly wrong. Better get
+                        // ClassCastException
+                        ChromiumLineBreakpoint breakpoint = (ChromiumLineBreakpoint) DebugPlugin.getDefault()
+                                .getBreakpointManager().getBreakpoint(marker);
+                        breakpointHandler.breakpointAdded(breakpoint);
+                        breakpoints.add(breakpoint);
+                    }
+                } catch (CoreException e) {
+                    Activator.log(e);
+                }
 
-			Script script = jsStackFrame.getCallFrame().getScript();
-			if (script == null) {
-				return null;
-			}
+            }
+        });
+    }
+
+    public void scriptLoaded(Script newScript) {
+        resourceManager.addScript(newScript);
+    }
 
-			IFile resource = resourceManager.getResource(script);
-			if (resource != null) {
-				return resource;
-			} else {
-				File file = PreviewerPlugin.getDefault().getHttpPreviewer().getLocalFile(script.getName());
-				if (file != null) {
-					try {
-						return EFS.getStore(file.toURI());
-					} catch (CoreException e) {
-						Activator.log(e);
-					}
-				}
-			}
-			return null;
-		}
-	};
+    public int getLineNumber(CallFrame stackFrame) {
+        int offset = 0;
+        Script script = stackFrame.getScript();
+        if (script != null) {
+            offset = script.getStartLine();
+        }
+        return offset + stackFrame.getLineNumber() + 1;
+    }
+
+    private final ISourceLookupDirector sourceLocator;
 
     public VmResource findVmResourceFromWorkspaceFile(IFile resource) throws CoreException {
         System.out.println(resource);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/WebApplicationSourceLocator.java	Tue Jun 08 15:33:30 2010 -0700
@@ -0,0 +1,102 @@
+/**
+ * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of the License "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Symbian Foundation - initial contribution.
+ * Contributors:
+ * Description:
+ * Overview:
+ * Details:
+ * Platforms/Drives/Compatibility:
+ * Assumptions/Requirement/Pre-requisites:
+ * Failures and causes:
+ */
+package org.symbian.tools.wrttools.debug.internal.launch;
+
+import java.io.File;
+
+import org.chromium.debug.core.model.StackFrame;
+import org.chromium.sdk.Script;
+import org.eclipse.core.filesystem.EFS;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.model.ISourceLocator;
+import org.eclipse.debug.core.model.IStackFrame;
+import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector;
+import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupParticipant;
+import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector;
+import org.eclipse.debug.core.sourcelookup.ISourceLookupParticipant;
+import org.symbian.tools.wrttools.debug.internal.Activator;
+import org.symbian.tools.wrttools.debug.internal.model.ResourceManager;
+import org.symbian.tools.wrttools.previewer.PreviewerPlugin;
+
+public final class WebApplicationSourceLocator extends AbstractSourceLookupDirector implements ISourceLocator,
+        ISourceLookupDirector {
+    public static final class WebApplicationSourceLookupParticipant extends AbstractSourceLookupParticipant {
+        private final ResourceManager resourceManager;
+
+        public WebApplicationSourceLookupParticipant(ResourceManager resourceManager) {
+            this.resourceManager = resourceManager;
+        }
+
+        public String getSourceName(Object object) throws CoreException {
+            Script script = null;
+            if (object instanceof StackFrame) {
+                script = ((StackFrame) object).getCallFrame().getScript();
+            } else if (object instanceof Script) {
+                script = (Script) object;
+            } else {
+                System.out.println("Source lookup request for " + object.getClass());
+            }
+            if (script != null) {
+                IFile resource = resourceManager.getResource(script);
+                if (resource != null) {
+                    return resource.getProjectRelativePath().toString();
+                }
+            }
+            return null;
+        }
+    }
+
+    private final ResourceManager resourceManager;
+
+    public WebApplicationSourceLocator(ResourceManager resourceManager) {
+        this.resourceManager = resourceManager;
+    }
+
+    public Object getSourceElement(IStackFrame stackFrame) {
+		if (stackFrame instanceof StackFrame == false) {
+			return null;
+		}
+		StackFrame jsStackFrame = (StackFrame) stackFrame;
+
+		Script script = jsStackFrame.getCallFrame().getScript();
+		if (script == null) {
+			return null;
+		}
+
+		IFile resource = resourceManager.getResource(script);
+		if (resource != null) {
+			return resource;
+		} else {
+			File file = PreviewerPlugin.getDefault().getHttpPreviewer().getLocalFile(script.getName());
+			if (file != null) {
+				try {
+					return EFS.getStore(file.toURI());
+				} catch (CoreException e) {
+					Activator.log(e);
+				}
+			}
+		}
+		return null;
+	}
+
+    public void initializeParticipants() {
+        addParticipants(new ISourceLookupParticipant[] { new WebApplicationSourceLookupParticipant(resourceManager) });
+    }
+}
\ No newline at end of file