/**
  * Returns the <code>IRubyBreakpoint</code> from the specified <code>IMember</code>
  *
  * @param element the element to get the breakpoint from
  * @return the current breakpoint from the element or <code>null</code>
  */
 protected IRubyBreakpoint getMethodBreakpoint(IMember element) {
   IBreakpointManager breakpointManager = DebugPlugin.getDefault().getBreakpointManager();
   IBreakpoint[] breakpoints =
       breakpointManager.getBreakpoints(RdtDebugModel.getModelIdentifier());
   if (element instanceof IMethod) {
     IMethod method = (IMethod) element;
     for (int i = 0; i < breakpoints.length; i++) {
       IBreakpoint breakpoint = breakpoints[i];
       if (breakpoint instanceof IRubyMethodBreakpoint) {
         IRubyMethodBreakpoint methodBreakpoint = (IRubyMethodBreakpoint) breakpoint;
         IMember container = null;
         try {
           container = BreakpointUtils.getMember(methodBreakpoint);
         } catch (CoreException e) {
           RdtDebugUiPlugin.log(e);
           return null;
         }
         if (container == null) {
           try {
             if (method
                     .getDeclaringType()
                     .getFullyQualifiedName()
                     .equals(methodBreakpoint.getTypeName())
                 && method.getElementName().equals(methodBreakpoint.getMethodName())) {
               return methodBreakpoint;
             }
           } catch (CoreException e) {
             RdtDebugUiPlugin.log(e);
           }
         } else {
           if (container instanceof IMethod) {
             if (method
                 .getDeclaringType()
                 .getFullyQualifiedName()
                 .equals(container.getDeclaringType().getFullyQualifiedName())) {
               if (method.isSimilar((IMethod) container)) {
                 return methodBreakpoint;
               }
             }
           }
         }
       }
     }
   }
   return null;
 }
 public void toggleBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
   ISelection sel = translateToMembers(part, selection);
   if (sel instanceof IStructuredSelection) {
     IMember member = (IMember) ((IStructuredSelection) sel).getFirstElement();
     int mtype = member.getElementType();
     if (mtype == IRubyElement.FIELD || mtype == IRubyElement.METHOD) {
       // remove line breakpoint if present first
       if (selection instanceof ITextSelection) {
         ITextSelection ts = (ITextSelection) selection;
         IType declaringType = member.getDeclaringType();
         IResource resource = BreakpointUtils.getBreakpointResource(declaringType);
         IRubyLineBreakpoint breakpoint =
             RdtDebugModel.lineBreakpointExists(resource, null, ts.getStartLine());
         if (breakpoint != null) {
           breakpoint.delete();
           return;
         }
         RootNode unit = parseRubyScript(getTextEditor(part));
         ValidBreakpointLocationLocator loc =
             new ValidBreakpointLocationLocator(unit, ts.getStartLine(), true);
         unit.accept(loc);
         if (loc.getLocationType() == ValidBreakpointLocationLocator.LOCATION_METHOD) {
           toggleMethodBreakpoints(part, sel);
         } else if (loc.getLocationType() == ValidBreakpointLocationLocator.LOCATION_FIELD) {
           toggleWatchpoints(part, ts);
         } else if (loc.getLocationType() == ValidBreakpointLocationLocator.LOCATION_LINE) {
           toggleLineBreakpoints(part, ts);
         } else {
           // fall back to old behavior, always create a line breakpoint
           toggleLineBreakpoints(part, selection, true);
         }
       }
     }
     // else if(member.getElementType() == IRubyElement.TYPE) {
     // toggleClassBreakpoints(part, sel);
     // }
     else {
       // fall back to old behavior, always create a line breakpoint
       toggleLineBreakpoints(part, selection, true);
     }
   } else {
     toggleLineBreakpoints(part, selection, true);
   }
 }
 /**
  * Returns whether the given part/selection is remote (viewing a repository)
  *
  * @param part
  * @param selection
  * @return
  */
 protected boolean isRemote(IWorkbenchPart part, ISelection selection) {
   if (selection instanceof IStructuredSelection) {
     IStructuredSelection ss = (IStructuredSelection) selection;
     Object element = ss.getFirstElement();
     if (element instanceof IMember) {
       IMember member = (IMember) element;
       return !member.getRubyProject().getProject().exists();
     }
   }
   ITextEditor editor = getTextEditor(part);
   if (editor != null) {
     IEditorInput input = editor.getEditorInput();
     Object adapter =
         Platform.getAdapterManager()
             .getAdapter(input, "org.eclipse.team.core.history.IFileRevision"); // $NON-NLS-1$
     return adapter != null;
   }
   return false;
 }