/** * Updates a watchpoint. Depending on the flags and on whether a breakpoint exists, this method * executes the toggle action. * * @param toggle Whether the toggle action is requested. If true and the breakpoint currently * exists, it will cause the toggle action to either remove breakpoint or edit its properties. * Otherwise a new breakpoint will be created. * @param interactive If true the toggle adapter should open a dialog before creating a * breakpoint, or open a properties dialog on an existing breakpoint. * @param part Workbench part where the toggle action is to be executed. * @param selection Variable on which to execute the toggle action. * @throws CoreException Any error in creating or editing the breakpoint. */ private void updateVariableWatchpoint( boolean toggle, boolean interactive, IWorkbenchPart part, IVariable variable) throws CoreException { String sourceHandle = getSourceHandle(variable); IResource resource = getElementResource(variable); String expression = getVariableName(variable); ICWatchpoint watchpoint = findWatchpoint(sourceHandle, resource, expression); if (toggle && watchpoint != null) { if (interactive) { CDebugUIUtils.editBreakpointProperties(part, watchpoint); } else { DebugPlugin.getDefault().getBreakpointManager().removeBreakpoint(watchpoint, true); } } else { int lineNumber = -1; int charStart = -1; int charEnd = -1; try { ISourceRange sourceRange = variable.getSourceRange(); if (sourceRange != null) { charStart = sourceRange.getStartPos(); charEnd = charStart + sourceRange.getLength(); if (charEnd <= 0) { charStart = -1; charEnd = -1; } lineNumber = sourceRange.getStartLine(); } } catch (CModelException e) { CDebugUIPlugin.log(e); } createWatchpoint( interactive, part, sourceHandle, resource, charStart, charEnd, lineNumber, expression, null, "0"); //$NON-NLS-1$ } }
private String getVariableName(IVariable variable) { return variable.getElementName(); }