1 package net.sourceforge.phpeclipse.xdebug.php.launching;
3 import java.util.ArrayList;
6 import net.sourceforge.phpeclipse.xdebug.core.PathMapItem;
7 import net.sourceforge.phpeclipse.xdebug.php.model.XDebugStackFrame;
9 import org.eclipse.core.resources.IFile;
10 import org.eclipse.core.runtime.CoreException;
11 import org.eclipse.core.runtime.IPath;
12 import org.eclipse.core.runtime.IStatus;
13 import org.eclipse.core.runtime.MultiStatus;
14 import org.eclipse.core.runtime.Path;
15 import org.eclipse.debug.core.DebugPlugin;
16 import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupParticipant;
17 import org.eclipse.debug.core.sourcelookup.ISourceContainer;
18 import org.eclipse.debug.internal.core.sourcelookup.SourceLookupMessages;
20 public class PHPSourceLookupParticipant extends AbstractSourceLookupParticipant {
23 * @see org.eclipse.debug.core.sourcelookup.ISourceLookupParticipant#getSourceName(Object)
25 public String getSourceName(Object object) throws CoreException {
26 if (object instanceof XDebugStackFrame) {
27 return ((XDebugStackFrame) object).getSourceName();
33 * @see org.eclipse.debug.core.sourcelookup.ISourceLookupParticipant#findSourceElements(java.lang.Object)
35 public Object[] findSourceElements(Object object) throws CoreException {
37 return new Object[] {};
39 XDebugStackFrame stackFrame = null;
40 if (object instanceof XDebugStackFrame) {
41 stackFrame = (XDebugStackFrame) object;
43 return new Object[] {};
47 CoreException single = null;
48 MultiStatus multiStatus = null;
50 if (isFindDuplicates()) {
51 results = new ArrayList();
54 String name = getSourceName(object);
55 if (name == null || name.length() == 0) {
56 return new Object[] {};
59 // here our stackframe is guaranteed not to be null
60 IPath sLocalPath = null;
62 if (((XDebugStackFrame) object).getThread() == null) {
63 IPath sPath = new Path(stackFrame.getFullName().getPath());
64 List pathMap = getDirector().getLaunchConfiguration()
65 .getAttribute(IXDebugConstants.ATTR_PHP_PATHMAP, (List) null);
67 PathMapItem pmi = null;
68 for (int k = 0; k < pathMap.size(); k++) {
69 pmi = new PathMapItem((String) pathMap.get(k));
71 IPath local = new Path(pmi.getLocalPath().toString())/* .removeFirstSegments(1) */;
72 IPath remote = new Path(pmi.getRemotePath().toString())/* .removeFirstSegments(1) */;
74 if (remote.matchingFirstSegments(sPath) == remote.segmentCount()) {
82 String Type = stackFrame.getType();
84 if (Type.equals("eval")) {
86 return results.toArray();
89 ISourceContainer[] containers = getSourceContainers();
90 for (int i = 0; i < containers.length; i++) {
91 ISourceContainer container = getDelegateContainer(containers[i]);
92 if (container == null) {
97 Object[] objects = container.findSourceElements(name);
98 if (objects.length > 0) {
99 if (isFindDuplicates()) {
100 if (((XDebugStackFrame) object).getThread() == null) {
101 addMatching(results, sLocalPath, objects);
106 if (objects.length == 1) {
109 return new Object[] { objects[0] };
112 } catch (CoreException e) {
113 if (single == null) {
115 } else if (multiStatus == null) {
116 multiStatus = new MultiStatus(DebugPlugin
117 .getUniqueIdentifier(), DebugPlugin.INTERNAL_ERROR,
118 new IStatus[] { single.getStatus() },
119 SourceLookupMessages.CompositeSourceContainer_0,
121 multiStatus.add(e.getStatus());
123 multiStatus.add(e.getStatus());
127 if (results == null) {
128 if (multiStatus != null) {
129 throw new CoreException(multiStatus);
130 } else if (single != null) {
135 return results.toArray();
138 static void addMatching(List results, IPath localPath, Object[] objects) {
139 if (results == null || localPath == null || objects == null) {
142 for (int j = 0; j < objects.length; j++) {
143 if (objects[j] == null || !(objects[j] instanceof IFile)) {
146 IFile file = (IFile) objects[j];
148 IPath path = new Path(file.getFullPath().toString());
149 if (localPath.matchingFirstSegments(path) == localPath
151 results.add(objects[j]);