plugins/org.symbian.tools.tmw.debug/src/org/symbian/tools/tmw/debug/internal/HtmlBreakpointProvider.java
author Eugene Ostroukhov <eugeneo@symbian.org>
Thu, 04 Nov 2010 15:22:02 -0700
changeset 495 0008ebdc0ec0
parent 485 df4f55e8569e
permissions -rw-r--r--
Launch configurations were updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
485
df4f55e8569e Fixed copyright headers and removed unneeded WRT mentions from TMW code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 484
diff changeset
     1
/*******************************************************************************
df4f55e8569e Fixed copyright headers and removed unneeded WRT mentions from TMW code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 484
diff changeset
     2
 * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies).
df4f55e8569e Fixed copyright headers and removed unneeded WRT mentions from TMW code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 484
diff changeset
     3
 * All rights reserved.
df4f55e8569e Fixed copyright headers and removed unneeded WRT mentions from TMW code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 484
diff changeset
     4
 * This component and the accompanying materials are made available
df4f55e8569e Fixed copyright headers and removed unneeded WRT mentions from TMW code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 484
diff changeset
     5
 * under the terms of the License "Eclipse Public License v1.0"
df4f55e8569e Fixed copyright headers and removed unneeded WRT mentions from TMW code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 484
diff changeset
     6
 * which accompanies this distribution, and is available
df4f55e8569e Fixed copyright headers and removed unneeded WRT mentions from TMW code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 484
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
df4f55e8569e Fixed copyright headers and removed unneeded WRT mentions from TMW code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 484
diff changeset
     8
 *
df4f55e8569e Fixed copyright headers and removed unneeded WRT mentions from TMW code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 484
diff changeset
     9
 * Initial Contributors:
df4f55e8569e Fixed copyright headers and removed unneeded WRT mentions from TMW code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 484
diff changeset
    10
 * Symbian Foundation - initial contribution.
df4f55e8569e Fixed copyright headers and removed unneeded WRT mentions from TMW code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 484
diff changeset
    11
 * Contributors:
df4f55e8569e Fixed copyright headers and removed unneeded WRT mentions from TMW code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 484
diff changeset
    12
 * Description:
df4f55e8569e Fixed copyright headers and removed unneeded WRT mentions from TMW code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 484
diff changeset
    13
 * Overview:
df4f55e8569e Fixed copyright headers and removed unneeded WRT mentions from TMW code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 484
diff changeset
    14
 * Details:
df4f55e8569e Fixed copyright headers and removed unneeded WRT mentions from TMW code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 484
diff changeset
    15
 * Platforms/Drives/Compatibility:
df4f55e8569e Fixed copyright headers and removed unneeded WRT mentions from TMW code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 484
diff changeset
    16
 * Assumptions/Requirement/Pre-requisites:
df4f55e8569e Fixed copyright headers and removed unneeded WRT mentions from TMW code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 484
diff changeset
    17
 * Failures and causes:
df4f55e8569e Fixed copyright headers and removed unneeded WRT mentions from TMW code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 484
diff changeset
    18
 *******************************************************************************/
471
06589bf52fa7 Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    19
package org.symbian.tools.tmw.debug.internal;
06589bf52fa7 Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    20
06589bf52fa7 Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    21
import org.chromium.debug.core.model.ChromiumLineBreakpoint;
06589bf52fa7 Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    22
import org.eclipse.core.resources.IResource;
06589bf52fa7 Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    23
import org.eclipse.core.runtime.CoreException;
06589bf52fa7 Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    24
import org.eclipse.core.runtime.IStatus;
06589bf52fa7 Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    25
import org.eclipse.core.runtime.Status;
06589bf52fa7 Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    26
import org.eclipse.debug.core.DebugPlugin;
06589bf52fa7 Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    27
import org.eclipse.jface.text.BadLocationException;
06589bf52fa7 Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    28
import org.eclipse.jface.text.IDocument;
06589bf52fa7 Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    29
import org.eclipse.jface.text.ITypedRegion;
06589bf52fa7 Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    30
import org.eclipse.ui.IEditorInput;
06589bf52fa7 Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    31
import org.eclipse.wst.html.core.text.IHTMLPartitions;
06589bf52fa7 Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    32
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
06589bf52fa7 Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    33
import org.eclipse.wst.sse.ui.internal.provisional.extensions.ISourceEditingTextTools;
06589bf52fa7 Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    34
import org.eclipse.wst.sse.ui.internal.provisional.extensions.breakpoint.IBreakpointProvider;
485
df4f55e8569e Fixed copyright headers and removed unneeded WRT mentions from TMW code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 484
diff changeset
    35
import org.symbian.tools.tmw.debug.internal.launch.ChromeToolsWorkspaceBridge;
471
06589bf52fa7 Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    36
06589bf52fa7 Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    37
@SuppressWarnings("restriction")
06589bf52fa7 Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    38
public class HtmlBreakpointProvider implements IBreakpointProvider {
06589bf52fa7 Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    39
484
f5df819c1852 Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 471
diff changeset
    40
    public IStatus addBreakpoint(IDocument document, IEditorInput input, int lineNumber, int offset)
f5df819c1852 Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 471
diff changeset
    41
            throws CoreException {
f5df819c1852 Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 471
diff changeset
    42
        boolean hasScript = hasJavaScript(document, lineNumber);
471
06589bf52fa7 Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    43
484
f5df819c1852 Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 471
diff changeset
    44
        if (hasScript) {
471
06589bf52fa7 Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    45
            ChromiumLineBreakpoint breakpoint = new ChromiumLineBreakpoint(getResource(input), lineNumber,
485
df4f55e8569e Fixed copyright headers and removed unneeded WRT mentions from TMW code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 484
diff changeset
    46
                    ChromeToolsWorkspaceBridge.DEBUG_MODEL_ID);
484
f5df819c1852 Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 471
diff changeset
    47
            DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(breakpoint);
f5df819c1852 Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 471
diff changeset
    48
        }
f5df819c1852 Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 471
diff changeset
    49
        return Status.OK_STATUS;
f5df819c1852 Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 471
diff changeset
    50
    }
471
06589bf52fa7 Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    51
484
f5df819c1852 Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 471
diff changeset
    52
    private boolean hasJavaScript(IDocument document, int lineNumber) {
f5df819c1852 Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 471
diff changeset
    53
        try {
f5df819c1852 Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 471
diff changeset
    54
            if (document instanceof IStructuredDocument) {
f5df819c1852 Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 471
diff changeset
    55
                IStructuredDocument doc = (IStructuredDocument) document;
f5df819c1852 Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 471
diff changeset
    56
                int lineOffset = doc.getLineOffset(lineNumber - 1);
f5df819c1852 Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 471
diff changeset
    57
                int lineLength = doc.getLineLength(lineNumber - 1);
f5df819c1852 Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 471
diff changeset
    58
                ITypedRegion[] computePartitioning = doc.computePartitioning(lineOffset, lineLength);
f5df819c1852 Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 471
diff changeset
    59
                for (ITypedRegion region : computePartitioning) {
f5df819c1852 Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 471
diff changeset
    60
                    if (IHTMLPartitions.SCRIPT.equals(region.getType())
f5df819c1852 Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 471
diff changeset
    61
                            || IHTMLPartitions.SCRIPT_EVENTHANDLER.equals(region.getType())) {
f5df819c1852 Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 471
diff changeset
    62
                        return true;
f5df819c1852 Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 471
diff changeset
    63
                    }
f5df819c1852 Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 471
diff changeset
    64
                }
f5df819c1852 Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 471
diff changeset
    65
            }
f5df819c1852 Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 471
diff changeset
    66
        } catch (BadLocationException e) {
f5df819c1852 Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 471
diff changeset
    67
            Activator.log(e);
f5df819c1852 Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 471
diff changeset
    68
        }
f5df819c1852 Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 471
diff changeset
    69
        return false;
f5df819c1852 Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 471
diff changeset
    70
    }
471
06589bf52fa7 Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    71
484
f5df819c1852 Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 471
diff changeset
    72
    public IResource getResource(IEditorInput input) {
f5df819c1852 Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 471
diff changeset
    73
        return (IResource) input.getAdapter(IResource.class);
f5df819c1852 Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 471
diff changeset
    74
    }
471
06589bf52fa7 Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    75
484
f5df819c1852 Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 471
diff changeset
    76
    public void setSourceEditingTextTools(ISourceEditingTextTools tools) {
f5df819c1852 Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 471
diff changeset
    77
        // Do nothing
f5df819c1852 Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 471
diff changeset
    78
    }
471
06589bf52fa7 Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    79
06589bf52fa7 Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    80
}