Java Code Examples for com.sun.jdi.StackFrame#location()

The following examples show how to use com.sun.jdi.StackFrame#location() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StackTraceRequestHandler.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
private Types.StackFrame convertDebuggerStackFrameToClient(StackFrame stackFrame, int frameId, IDebugAdapterContext context)
        throws URISyntaxException, AbsentInformationException {
    Location location = stackFrame.location();
    Method method = location.method();
    Types.Source clientSource = this.convertDebuggerSourceToClient(location, context);
    String methodName = formatMethodName(method, true, true);
    int lineNumber = AdapterUtils.convertLineNumber(location.lineNumber(), context.isDebuggerLinesStartAt1(), context.isClientLinesStartAt1());
    // Line number returns -1 if the information is not available; specifically, always returns -1 for native methods.
    if (lineNumber < 0) {
        if (method.isNative()) {
            // For native method, display a tip text "native method" in the Call Stack View.
            methodName += "[native method]";
        } else {
            // For other unavailable method, such as lambda expression's built-in methods run/accept/apply,
            // display "Unknown Source" in the Call Stack View.
            clientSource = null;
        }
    }
    return new Types.StackFrame(frameId, methodName, clientSource, lineNumber, context.isClientColumnsStartAt1() ? 1 : 0);
}
 
Example 2
Source File: JdtUtils.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Given a stack frame, find the target java project that the associated source file belongs to.
 *
 * @param stackFrame
 *                  the stack frame.
 * @param containers
 *                  the source container list.
 * @return the java project.
 */
public static IJavaProject findProject(StackFrame stackFrame, ISourceContainer[] containers) {
    Location location = stackFrame.location();
    try {
        Object sourceElement = findSourceElement(location.sourcePath(), containers);
        if (sourceElement instanceof IResource) {
            return JavaCore.create(((IResource) sourceElement).getProject());
        } else if (sourceElement instanceof IClassFile) {
            IJavaProject javaProject = ((IClassFile) sourceElement).getJavaProject();
            if (javaProject != null) {
                return javaProject;
            }
        }
    } catch (AbsentInformationException e) {
        // When the compiled .class file doesn't contain debug source information, return null.
    }
    return null;
}