plugins/org.symbian.tools.tmw.debug/src/org/symbian/tools/tmw/debug/internal/launch/TmwLabelProvider.java
changeset 485 df4f55e8569e
equal deleted inserted replaced
484:f5df819c1852 485:df4f55e8569e
       
     1 /*******************************************************************************
       
     2  * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of the License "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Symbian Foundation - initial contribution.
       
    11  * Contributors:
       
    12  * Description:
       
    13  * Overview:
       
    14  * Details:
       
    15  * Platforms/Drives/Compatibility:
       
    16  * Assumptions/Requirement/Pre-requisites:
       
    17  * Failures and causes:
       
    18  *******************************************************************************/
       
    19 package org.symbian.tools.tmw.debug.internal.launch;
       
    20 
       
    21 import org.chromium.debug.core.model.DebugTargetImpl;
       
    22 import org.chromium.debug.core.model.JavascriptThread;
       
    23 import org.chromium.debug.core.model.Messages;
       
    24 import org.chromium.debug.core.model.StackFrame;
       
    25 import org.chromium.debug.core.model.WorkspaceBridge.JsLabelProvider;
       
    26 import org.chromium.sdk.CallFrame;
       
    27 import org.chromium.sdk.DebugContext;
       
    28 import org.chromium.sdk.ExceptionData;
       
    29 import org.chromium.sdk.Script;
       
    30 import org.eclipse.core.filesystem.IFileStore;
       
    31 import org.eclipse.core.resources.IFile;
       
    32 import org.eclipse.debug.core.DebugException;
       
    33 import org.eclipse.osgi.util.NLS;
       
    34 
       
    35 public class TmwLabelProvider implements JsLabelProvider {
       
    36 
       
    37     public String getStackFrameLabel(StackFrame stackFrame) throws DebugException {
       
    38         CallFrame callFrame = stackFrame.getCallFrame();
       
    39         String name = callFrame.getFunctionName();
       
    40         Script script = callFrame.getScript();
       
    41         if (script == null) {
       
    42             return "<unknown>";
       
    43         }
       
    44         Object element = stackFrame.getLaunch().getSourceLocator().getSourceElement(stackFrame);
       
    45         if (element instanceof IFile) {
       
    46             IFile resource = (IFile) element;
       
    47             int line = script.getStartLine() + stackFrame.getLineNumber();
       
    48             if (line != -1) {
       
    49                 final String resourcePath = resource.getProjectRelativePath().toString();
       
    50                 name = NLS.bind("{0} [{1}:{2}]", new Object[] { name, resourcePath, line });
       
    51             }
       
    52         } else if (element instanceof IFileStore) {
       
    53             return "(WRT System Library)";
       
    54         }
       
    55         return name;
       
    56     }
       
    57 
       
    58     public String getTargetLabel(DebugTargetImpl debugTarget) throws DebugException {
       
    59         return "WRT Runtime";
       
    60     }
       
    61 
       
    62     public String getThreadLabel(JavascriptThread thread) throws DebugException {
       
    63         return NLS.bind("JavaScript Thread ({0})", getThreadStateLabel(thread));
       
    64     }
       
    65 
       
    66     private String getThreadStateLabel(JavascriptThread thread) {
       
    67         if (thread.isSuspended()) {
       
    68             DebugContext context = thread.getDebugTarget().getDebugContext();
       
    69             ExceptionData exceptionData = context.getExceptionData();
       
    70             if (exceptionData != null) {
       
    71                 return NLS.bind(Messages.JsThread_ThreadLabelSuspendedExceptionFormat,
       
    72                         exceptionData.getExceptionMessage());
       
    73             } else {
       
    74                 return Messages.JsThread_ThreadLabelSuspended;
       
    75             }
       
    76         } else {
       
    77             return Messages.JsThread_ThreadLabelRunning;
       
    78         }
       
    79     }
       
    80 
       
    81 }