cdt/cdt_6_0_x/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/editors/DebugTextHover.java
author dadubrow
Tue, 10 Nov 2009 09:58:50 -0600
changeset 111 c2563c416525
parent 110 9262ca4bdfff
permissions -rw-r--r--
merge debug text hover support with CDT
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     1
/*******************************************************************************
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     2
 * Copyright (c) 2000, 2007 QNX Software Systems and others.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     3
 * All rights reserved. This program and the accompanying materials
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     4
 * are made available under the terms of the Eclipse Public License v1.0
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     5
 * which accompanies this distribution, and is available at
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     6
 * http://www.eclipse.org/legal/epl-v10.html
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     7
 *
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     8
 * Contributors:
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     9
 *     QNX Software Systems - Initial API and implementation
110
9262ca4bdfff Bug 10071 - add support for debug hovers to DSF
dadubrow
parents: 37
diff changeset
    10
 *     Nokia - Refactored into CDI specific implementation of AbstractDebugTextHover
9262ca4bdfff Bug 10071 - add support for debug hovers to DSF
dadubrow
parents: 37
diff changeset
    11
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    12
 *******************************************************************************/
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    13
package org.eclipse.cdt.debug.internal.ui.editors;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    14
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    15
import org.eclipse.cdt.debug.core.model.ICStackFrame;
110
9262ca4bdfff Bug 10071 - add support for debug hovers to DSF
dadubrow
parents: 37
diff changeset
    16
import org.eclipse.cdt.debug.ui.editors.AbstractDebugTextHover;
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    17
import org.eclipse.core.runtime.IAdaptable;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    18
import org.eclipse.debug.core.DebugException;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    19
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    20
/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    21
 * The text hovering support for C/C++ debugger.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    22
 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    23
110
9262ca4bdfff Bug 10071 - add support for debug hovers to DSF
dadubrow
parents: 37
diff changeset
    24
public class DebugTextHover extends AbstractDebugTextHover {
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    25
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    26
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    27
	 * Returns the evaluation stack frame, or <code>null</code> if none.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    28
	 * 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    29
	 * @return the evaluation stack frame, or <code>null</code> if none
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    30
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    31
	protected ICStackFrame getFrame() {
111
c2563c416525 merge debug text hover support with CDT
dadubrow
parents: 110
diff changeset
    32
        IAdaptable adaptable = getSelectionAdaptable();
c2563c416525 merge debug text hover support with CDT
dadubrow
parents: 110
diff changeset
    33
        if (adaptable != null) {
c2563c416525 merge debug text hover support with CDT
dadubrow
parents: 110
diff changeset
    34
            return (ICStackFrame) adaptable.getAdapter(ICStackFrame.class);
c2563c416525 merge debug text hover support with CDT
dadubrow
parents: 110
diff changeset
    35
        }
c2563c416525 merge debug text hover support with CDT
dadubrow
parents: 110
diff changeset
    36
        return null;
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    37
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    38
110
9262ca4bdfff Bug 10071 - add support for debug hovers to DSF
dadubrow
parents: 37
diff changeset
    39
	@Override
9262ca4bdfff Bug 10071 - add support for debug hovers to DSF
dadubrow
parents: 37
diff changeset
    40
	protected boolean canEvaluate() {
9262ca4bdfff Bug 10071 - add support for debug hovers to DSF
dadubrow
parents: 37
diff changeset
    41
		ICStackFrame frame = getFrame();
9262ca4bdfff Bug 10071 - add support for debug hovers to DSF
dadubrow
parents: 37
diff changeset
    42
		if (frame != null)
9262ca4bdfff Bug 10071 - add support for debug hovers to DSF
dadubrow
parents: 37
diff changeset
    43
			return frame.canEvaluate();
9262ca4bdfff Bug 10071 - add support for debug hovers to DSF
dadubrow
parents: 37
diff changeset
    44
		
9262ca4bdfff Bug 10071 - add support for debug hovers to DSF
dadubrow
parents: 37
diff changeset
    45
		return false;
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    46
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    47
110
9262ca4bdfff Bug 10071 - add support for debug hovers to DSF
dadubrow
parents: 37
diff changeset
    48
	@Override
9262ca4bdfff Bug 10071 - add support for debug hovers to DSF
dadubrow
parents: 37
diff changeset
    49
	protected String evaluateExpression(String expression) {
9262ca4bdfff Bug 10071 - add support for debug hovers to DSF
dadubrow
parents: 37
diff changeset
    50
		ICStackFrame frame = getFrame();
9262ca4bdfff Bug 10071 - add support for debug hovers to DSF
dadubrow
parents: 37
diff changeset
    51
		String result = null;
9262ca4bdfff Bug 10071 - add support for debug hovers to DSF
dadubrow
parents: 37
diff changeset
    52
		try {
9262ca4bdfff Bug 10071 - add support for debug hovers to DSF
dadubrow
parents: 37
diff changeset
    53
			result = frame.evaluateExpressionToString(expression);
9262ca4bdfff Bug 10071 - add support for debug hovers to DSF
dadubrow
parents: 37
diff changeset
    54
		} catch (DebugException e) {
9262ca4bdfff Bug 10071 - add support for debug hovers to DSF
dadubrow
parents: 37
diff changeset
    55
			// ignore
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    56
		}
110
9262ca4bdfff Bug 10071 - add support for debug hovers to DSF
dadubrow
parents: 37
diff changeset
    57
		return result;
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    58
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    59
}