1) Implement variable hover for XDebug.
authorrobekras <robekras>
Wed, 16 Mar 2011 19:59:21 +0000 (19:59 +0000)
committerrobekras <robekras>
Wed, 16 Mar 2011 19:59:21 +0000 (19:59 +0000)
net.sourceforge.phpeclipse.debug.ui/META-INF/MANIFEST.MF
net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/PHPDebugHover.java

index 58cec46..9f6b68b 100644 (file)
@@ -26,3 +26,4 @@ Require-Bundle: org.eclipse.ui.ide,
  net.sourceforge.phpeclipse.ui
 Bundle-ActivationPolicy: lazy
 Bundle-RequiredExecutionEnvironment: J2SE-1.4
+Import-Package: net.sourceforge.phpeclipse.xdebug.php.model
index 4c566d6..2826591 100644 (file)
@@ -1,10 +1,10 @@
 /*******************************************************************************
  * Copyright (c) 2000, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials 
+ * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Common Public License v1.0
  * which accompanies this distribution, and is available at
  * http://www.eclipse.org/legal/cpl-v10.html
- * 
+ *
  * Contributors:
  *     IBM Corporation - initial API and implementation
  *******************************************************************************/
@@ -17,6 +17,10 @@ import net.sourceforge.phpdt.internal.ui.text.JavaWordFinder;
 import net.sourceforge.phpdt.ui.PreferenceConstants;
 import net.sourceforge.phpdt.ui.text.java.hover.IJavaEditorTextHover;
 
+import net.sourceforge.phpeclipse.xdebug.php.model.XDebugStackFrame;
+import net.sourceforge.phpeclipse.xdebug.php.model.XDebugTarget;
+import net.sourceforge.phpeclipse.xdebug.php.model.XDebugValue;
+
 import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.debug.core.DebugException;
 import org.eclipse.debug.core.model.IValue;
@@ -32,6 +36,8 @@ import org.eclipse.jface.text.ITextHoverExtension;
 import org.eclipse.jface.text.ITextViewer;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeSelection;
+import org.eclipse.jface.viewers.TreePath;
 //import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.IEditorPart;
@@ -49,7 +55,7 @@ public class PHPDebugHover implements IJavaEditorTextHover,
 
        /*
         * (non-Javadoc)
-        * 
+        *
         * @see org.eclipse.ui.IPartListener#partActivated(org.eclipse.ui.IWorkbenchPart)
         */
        public void partActivated(IWorkbenchPart part) {
@@ -57,7 +63,7 @@ public class PHPDebugHover implements IJavaEditorTextHover,
 
        /*
         * (non-Javadoc)
-        * 
+        *
         * @see org.eclipse.ui.IPartListener#partBroughtToTop(org.eclipse.ui.IWorkbenchPart)
         */
        public void partBroughtToTop(IWorkbenchPart part) {
@@ -65,7 +71,7 @@ public class PHPDebugHover implements IJavaEditorTextHover,
 
        /*
         * (non-Javadoc)
-        * 
+        *
         * @see org.eclipse.ui.IPartListener#partClosed(org.eclipse.ui.IWorkbenchPart)
         */
        public void partClosed(IWorkbenchPart part) {
@@ -80,7 +86,7 @@ public class PHPDebugHover implements IJavaEditorTextHover,
 
        /*
         * (non-Javadoc)
-        * 
+        *
         * @see org.eclipse.ui.IPartListener#partDeactivated(org.eclipse.ui.IWorkbenchPart)
         */
        public void partDeactivated(IWorkbenchPart part) {
@@ -88,7 +94,7 @@ public class PHPDebugHover implements IJavaEditorTextHover,
 
        /*
         * (non-Javadoc)
-        * 
+        *
         * @see org.eclipse.ui.IPartListener#partOpened(org.eclipse.ui.IWorkbenchPart)
         */
        public void partOpened(IWorkbenchPart part) {
@@ -96,7 +102,7 @@ public class PHPDebugHover implements IJavaEditorTextHover,
 
        /*
         * (non-Javadoc)
-        * 
+        *
         * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart,
         *      org.eclipse.jface.viewers.ISelection)
         */
@@ -109,7 +115,7 @@ public class PHPDebugHover implements IJavaEditorTextHover,
 
        /*
         * (non-Javadoc)
-        * 
+        *
         * @see org.eclipse.jdt.ui.text.java.hover.IJavaEditorTextHover#setEditor(org.eclipse.ui.IEditorPart)
         */
        public void setEditor(IEditorPart editor) {
@@ -131,7 +137,7 @@ public class PHPDebugHover implements IJavaEditorTextHover,
 
        /*
         * (non-Javadoc)
-        * 
+        *
         * @see org.eclipse.jface.text.ITextHover#getHoverRegion(org.eclipse.jface.text.ITextViewer,
         *      int)
         */
@@ -142,7 +148,7 @@ public class PHPDebugHover implements IJavaEditorTextHover,
        /**
         * Returns the stack frame in which to search for variables, or
         * <code>null</code> if none.
-        * 
+        *
         * @return the stack frame in which to search for variables, or
         *         <code>null</code> if none
         */
@@ -160,27 +166,64 @@ public class PHPDebugHover implements IJavaEditorTextHover,
                return null;
        }
 
+    protected XDebugStackFrame getXDebugFrame() {
+        if (fSelection instanceof IStructuredSelection) {
+            IStructuredSelection selection = (IStructuredSelection) fSelection;
+            if (selection.size() == 1) {
+                Object el = selection.getFirstElement();
+                if (el instanceof IAdaptable) {
+                    return (XDebugStackFrame) ((IAdaptable) el)
+                            .getAdapter(XDebugStackFrame.class);
+                }
+            }
+        }
+        return null;
+    }
+
        /*
         * (non-Javadoc)
-        * 
+        *
         * @see org.eclipse.jface.text.ITextHover#getHoverInfo(org.eclipse.jface.text.ITextViewer,
         *      org.eclipse.jface.text.IRegion)
         */
        public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
-               PHPStackFrame frame = getFrame();
-               if (frame != null) {
-                       try {
+           IVariable        variable = null;
+               PHPStackFrame    frameDBG = null;
+               XDebugStackFrame frameXD  = null;
+
+               TreePath paths[] = ((ITreeSelection) fSelection).getPaths ();
+               Object target = paths[0].getSegment (1);
+
+               if (target.getClass().getName ().equals ("net.sourceforge.phpeclipse.xdebug.php.model.XDebugTarget") ) {
+                   frameXD = getXDebugFrame ();
+               }
+               else {
+                   frameDBG = getFrame();
+               }
 
+               if ((frameDBG != null) || (frameXD != null)) {
+                       try {
                                IDocument document = textViewer.getDocument();
+
                                if (document == null)
                                        return null;
 
-                               String variableName = document.get(hoverRegion.getOffset(),
-                                               hoverRegion.getLength());
+                               String variableName = document.get (hoverRegion.getOffset(), hoverRegion.getLength());
 
                                StringBuffer buffer = new StringBuffer();
                                try {
-                                       IVariable variable = frame.findVariable(variableName);
+                                   if (frameDBG != null) {
+                                       variable = frameDBG.findVariable(variableName);
+                                   }
+                                   else if (frameXD != null) {
+                                   if (variableName.startsWith ("$")) {
+                                       variable = frameXD.findVariable (variableName.substring (1));
+                                   }
+                                   else {
+                                           variable = frameXD.findVariable (variableName);
+                                   }
+                                   }
+
                                        if (variable != null) {
                                                appendVariable(buffer, variable);
                                        }
@@ -222,7 +265,8 @@ public class PHPDebugHover implements IJavaEditorTextHover,
                        buffer.append(" \""); //$NON-NLS-1$
                        buffer.append(value);
                        buffer.append('"');
-               } else if (type.equals("boolean")) { //$NON-NLS-1$
+               } else if (type.equals("boolean") ||          // in dbg it's boolean
+                          type.equals("bool")) {             // in XDebug it's bool   $NON-NLS-1$
                        buffer.append(' ');
                        buffer.append(value);
                } else {
@@ -236,14 +280,19 @@ public class PHPDebugHover implements IJavaEditorTextHover,
 
        private static String getTypeName(IVariable variable) throws DebugException {
                IValue value = variable.getValue();
+
                if (value instanceof PHPValue)
                        return ((PHPValue) value).getReferenceTypeName();
+
+               if (value instanceof XDebugValue)
+                       return ((XDebugValue) value).getReferenceTypeName ();
+
                return null;
        }
 
        /*
         * (non-Javadoc)
-        * 
+        *
         * @see org.eclipse.jface.text.ITextHoverExtension#getInformationControlCreator()
         */
 //     public IInformationControlCreator getInformationControlCreator() {
@@ -266,7 +315,7 @@ public class PHPDebugHover implements IJavaEditorTextHover,
 
        /*
         * (non-Javadoc)
-        * 
+        *
         * @see org.eclipse.jface.text.ITextHoverExtension#getHoverControlCreator()
         */
        public IInformationControlCreator getHoverControlCreator() {