org.chromium.debug.core/src/org/chromium/debug/core/model/LineBreakpointAdapter.java
changeset 52 f577ea64429e
parent 2 e4420d2515f1
child 355 8726e95bcbba
equal deleted inserted replaced
49:e64c52f5ee56 52:f577ea64429e
     2 // Use of this source code is governed by a BSD-style license that can be
     2 // Use of this source code is governed by a BSD-style license that can be
     3 // found in the LICENSE file.
     3 // found in the LICENSE file.
     4 
     4 
     5 package org.chromium.debug.core.model;
     5 package org.chromium.debug.core.model;
     6 
     6 
     7 import org.chromium.debug.core.ChromiumDebugPlugin;
       
     8 import org.chromium.debug.core.util.ChromiumDebugPluginUtil;
     7 import org.chromium.debug.core.util.ChromiumDebugPluginUtil;
     9 import org.eclipse.core.resources.IResource;
     8 import org.eclipse.core.resources.IResource;
    10 import org.eclipse.core.runtime.CoreException;
     9 import org.eclipse.core.runtime.CoreException;
    11 import org.eclipse.debug.core.DebugPlugin;
    10 import org.eclipse.debug.core.DebugPlugin;
    12 import org.eclipse.debug.core.model.IBreakpoint;
    11 import org.eclipse.debug.core.model.IBreakpoint;
    18 import org.eclipse.ui.texteditor.ITextEditor;
    17 import org.eclipse.ui.texteditor.ITextEditor;
    19 
    18 
    20 /**
    19 /**
    21  * Adapter to create breakpoints in JS files.
    20  * Adapter to create breakpoints in JS files.
    22  */
    21  */
    23 public class LineBreakpointAdapter implements IToggleBreakpointsTarget {
    22 public abstract class LineBreakpointAdapter implements IToggleBreakpointsTarget {
       
    23 
       
    24   public static class ForVirtualProject extends LineBreakpointAdapter {
       
    25     @Override
       
    26     protected ITextEditor getEditor(IWorkbenchPart part) {
       
    27       if (part instanceof ITextEditor) {
       
    28         ITextEditor editorPart = (ITextEditor) part;
       
    29         IResource resource = (IResource) editorPart.getEditorInput().getAdapter(IResource.class);
       
    30         if (resource != null &&
       
    31             ChromiumDebugPluginUtil.CHROMIUM_EXTENSION.equals(resource.getFileExtension())) {
       
    32           return editorPart;
       
    33         }
       
    34       }
       
    35       return null;
       
    36     }
       
    37 
       
    38     @Override
       
    39     protected String getDebugModelId() {
       
    40       return VProjectWorkspaceBridge.DEBUG_MODEL_ID;
       
    41     }
       
    42   }
    24 
    43 
    25   public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection)
    44   public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection)
    26       throws CoreException {
    45       throws CoreException {
    27     ITextEditor textEditor = getEditor(part);
    46     ITextEditor textEditor = getEditor(part);
    28     if (textEditor != null) {
    47     if (textEditor != null) {
    29       IResource resource = (IResource) textEditor.getEditorInput().getAdapter(IResource.class);
    48       IResource resource = (IResource) textEditor.getEditorInput().getAdapter(IResource.class);
    30       ITextSelection textSelection = (ITextSelection) selection;
    49       ITextSelection textSelection = (ITextSelection) selection;
    31       int lineNumber = textSelection.getStartLine();
    50       int lineNumber = textSelection.getStartLine();
    32       IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(
    51       IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(
    33           ChromiumDebugPlugin.DEBUG_MODEL_ID);
    52           getDebugModelId());
    34       for (int i = 0; i < breakpoints.length; i++) {
    53       for (int i = 0; i < breakpoints.length; i++) {
    35         IBreakpoint breakpoint = breakpoints[i];
    54         IBreakpoint breakpoint = breakpoints[i];
    36         if (resource.equals(breakpoint.getMarker().getResource())) {
    55         if (resource.equals(breakpoint.getMarker().getResource())) {
    37           if (((ILineBreakpoint) breakpoint).getLineNumber() == lineNumber + 1) {
    56           if (((ILineBreakpoint) breakpoint).getLineNumber() == lineNumber + 1) {
    38             // remove
    57             // remove
    57    * part, or <code>null</code> if none.
    76    * part, or <code>null</code> if none.
    58    * @param part workbench part
    77    * @param part workbench part
    59    * @return the editor being used to edit a PDA file, associated with the given
    78    * @return the editor being used to edit a PDA file, associated with the given
    60    *         part, or <code>null</code> if none
    79    *         part, or <code>null</code> if none
    61    */
    80    */
    62   protected ITextEditor getEditor(IWorkbenchPart part) {
    81   protected abstract ITextEditor getEditor(IWorkbenchPart part);
    63     if (part instanceof ITextEditor) {
    82 
    64       ITextEditor editorPart = (ITextEditor) part;
    83   protected abstract String getDebugModelId();
    65       IResource resource = (IResource) editorPart.getEditorInput().getAdapter(IResource.class);
       
    66       if (resource != null &&
       
    67           ChromiumDebugPluginUtil.CHROMIUM_EXTENSION.equals(resource.getFileExtension())) {
       
    68         return editorPart;
       
    69       }
       
    70     }
       
    71     return null;
       
    72   }
       
    73 
    84 
    74   public void toggleMethodBreakpoints(IWorkbenchPart part, ISelection selection)
    85   public void toggleMethodBreakpoints(IWorkbenchPart part, ISelection selection)
    75       throws CoreException {
    86       throws CoreException {
    76     // TODO(apavlov): Implement method breakpoints if feasible.
    87     // TODO(apavlov): Implement method breakpoints if feasible.
    77   }
    88   }