示例#1
0
 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);
   }
 }