|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
|
2 // Use of this source code is governed by a BSD-style license that can be |
|
3 // found in the LICENSE file. |
|
4 |
|
5 package org.chromium.debug.core; |
|
6 |
|
7 import org.chromium.debug.core.model.ResourceManager; |
|
8 import org.chromium.debug.core.model.StackFrame; |
|
9 import org.chromium.debug.core.model.VmResourceId; |
|
10 import org.chromium.sdk.Breakpoint; |
|
11 import org.chromium.sdk.Script; |
|
12 import org.eclipse.core.resources.IProject; |
|
13 import org.eclipse.core.runtime.CoreException; |
|
14 import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector; |
|
15 import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupParticipant; |
|
16 import org.eclipse.debug.core.sourcelookup.ISourceLookupParticipant; |
|
17 |
|
18 /** |
|
19 * A source lookup director implementation that provides a simple participant and |
|
20 * accepts instance of virtual project once it is created. |
|
21 */ |
|
22 public class ChromiumSourceDirector extends AbstractSourceLookupDirector { |
|
23 private volatile ResourceManager resourceManager = null; |
|
24 private volatile IProject project = null; |
|
25 private volatile ReverseSourceLookup reverseSourceLookup = null; |
|
26 |
|
27 |
|
28 public void initializeParticipants() { |
|
29 ISourceLookupParticipant participant = new AbstractSourceLookupParticipant() { |
|
30 public String getSourceName(Object object) throws CoreException { |
|
31 Script script = null; |
|
32 if (object instanceof Script) { |
|
33 script = (Script) object; |
|
34 } else if (object instanceof StackFrame) { |
|
35 StackFrame jsStackFrame = (StackFrame) object; |
|
36 script = jsStackFrame.getCallFrame().getScript(); |
|
37 } else if (object instanceof Breakpoint) { |
|
38 Breakpoint breakpoint = (Breakpoint) object; |
|
39 return breakpoint.getScriptName(); |
|
40 } |
|
41 if (script == null) { |
|
42 return null; |
|
43 } |
|
44 |
|
45 return VmResourceId.forScript(script).getEclipseSourceName(); |
|
46 } |
|
47 }; |
|
48 addParticipants(new ISourceLookupParticipant[] { participant } ); |
|
49 } |
|
50 |
|
51 public void initializeVProjectContainers(IProject project, ResourceManager resourceManager) { |
|
52 this.resourceManager = resourceManager; |
|
53 this.project = project; |
|
54 this.reverseSourceLookup = new ReverseSourceLookup(this); |
|
55 } |
|
56 |
|
57 public ReverseSourceLookup getReverseSourceLookup() { |
|
58 return reverseSourceLookup; |
|
59 } |
|
60 |
|
61 public ResourceManager getResourceManager() { |
|
62 return resourceManager; |
|
63 } |
|
64 |
|
65 IProject getProject() { |
|
66 return project; |
|
67 } |
|
68 } |