Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/breakpoints/PDAToggleWatchpointsTarget.java')
-rw-r--r--org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/breakpoints/PDAToggleWatchpointsTarget.java176
1 files changed, 88 insertions, 88 deletions
diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/breakpoints/PDAToggleWatchpointsTarget.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/breakpoints/PDAToggleWatchpointsTarget.java
index 1aef74728..0fe58af12 100644
--- a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/breakpoints/PDAToggleWatchpointsTarget.java
+++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/breakpoints/PDAToggleWatchpointsTarget.java
@@ -42,121 +42,121 @@ import org.eclipse.ui.texteditor.ITextEditor;
*/
public class PDAToggleWatchpointsTarget extends PDABreakpointAdapter {
- final private boolean fAccessModeEnabled;
- final private boolean fModificationModeEnabled;
+ final private boolean fAccessModeEnabled;
+ final private boolean fModificationModeEnabled;
- PDAToggleWatchpointsTarget(boolean access, boolean modification) {
- fAccessModeEnabled = access;
- fModificationModeEnabled = modification;
- }
+ PDAToggleWatchpointsTarget(boolean access, boolean modification) {
+ fAccessModeEnabled = access;
+ fModificationModeEnabled = modification;
+ }
- @Override
+ @Override
public boolean canToggleWatchpoints(IWorkbenchPart part, ISelection selection) {
- if (super.canToggleWatchpoints(part, selection)) {
- return true;
- } else {
- if (selection instanceof IStructuredSelection) {
- IStructuredSelection ss = (IStructuredSelection)selection;
- return ss.getFirstElement() instanceof PDAVariable;
- }
- }
- return false;
- }
+ if (super.canToggleWatchpoints(part, selection)) {
+ return true;
+ } else {
+ if (selection instanceof IStructuredSelection) {
+ IStructuredSelection ss = (IStructuredSelection)selection;
+ return ss.getFirstElement() instanceof PDAVariable;
+ }
+ }
+ return false;
+ }
@Override
public void toggleWatchpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
- String[] variableAndFunctionName = getVariableAndFunctionName(part, selection);
-
- if (variableAndFunctionName != null && part instanceof ITextEditor && selection instanceof ITextSelection) {
- // Selection inside text editor. Create a watchpoint based on
- // current source line.
- ITextEditor editorPart = (ITextEditor)part;
- int lineNumber = ((ITextSelection)selection).getStartLine();
- IResource resource = editorPart.getEditorInput().getAdapter(IResource.class);
- String var = variableAndFunctionName[0];
- String fcn = variableAndFunctionName[1];
- toggleWatchpoint(resource, lineNumber, fcn, var, fAccessModeEnabled, fModificationModeEnabled);
- } else if (selection instanceof IStructuredSelection &&
- ((IStructuredSelection)selection).getFirstElement() instanceof PDAVariable )
- {
- // Selection is inside a variables view. Create a watchpoint
- // using information from the variable. Retrieving information
- // from the model requires performing source lookup which should be
- // done on a background thread.
- final PDAVariable var = (PDAVariable)((IStructuredSelection)selection).getFirstElement();
- final PDAStackFrame frame = var.getStackFrame();
- final Shell shell = part.getSite().getShell();
+ String[] variableAndFunctionName = getVariableAndFunctionName(part, selection);
+
+ if (variableAndFunctionName != null && part instanceof ITextEditor && selection instanceof ITextSelection) {
+ // Selection inside text editor. Create a watchpoint based on
+ // current source line.
+ ITextEditor editorPart = (ITextEditor)part;
+ int lineNumber = ((ITextSelection)selection).getStartLine();
+ IResource resource = editorPart.getEditorInput().getAdapter(IResource.class);
+ String var = variableAndFunctionName[0];
+ String fcn = variableAndFunctionName[1];
+ toggleWatchpoint(resource, lineNumber, fcn, var, fAccessModeEnabled, fModificationModeEnabled);
+ } else if (selection instanceof IStructuredSelection &&
+ ((IStructuredSelection)selection).getFirstElement() instanceof PDAVariable )
+ {
+ // Selection is inside a variables view. Create a watchpoint
+ // using information from the variable. Retrieving information
+ // from the model requires performing source lookup which should be
+ // done on a background thread.
+ final PDAVariable var = (PDAVariable)((IStructuredSelection)selection).getFirstElement();
+ final PDAStackFrame frame = var.getStackFrame();
+ final Shell shell = part.getSite().getShell();
new Job("Toggle PDA Watchpoint") { //$NON-NLS-1$
- { setSystem(true); }
+ { setSystem(true); }
- @Override
+ @Override
protected IStatus run(IProgressMonitor monitor) {
- try {
- IFile file = getResource(var.getStackFrame());
- String varName = var.getName();
- int line = findLine(file, varName);
- toggleWatchpoint(file, line, frame.getName(), varName,
- fAccessModeEnabled, fModificationModeEnabled);
- } catch (final CoreException e) {
- // Need to switch back to the UI thread to show the error
- // dialog.
+ try {
+ IFile file = getResource(var.getStackFrame());
+ String varName = var.getName();
+ int line = findLine(file, varName);
+ toggleWatchpoint(file, line, frame.getName(), varName,
+ fAccessModeEnabled, fModificationModeEnabled);
+ } catch (final CoreException e) {
+ // Need to switch back to the UI thread to show the error
+ // dialog.
new WorkbenchJob(shell.getDisplay(), "Toggle PDA Watchpoint") { //$NON-NLS-1$
- { setSystem(true); }
+ { setSystem(true); }
- @Override
+ @Override
public IStatus runInUIThread(IProgressMonitor submonitor) {
ErrorDialog.openError(shell, "Failed to create PDA watchpoint", "Failed to create PDA watchpoint.\n", e.getStatus()); //$NON-NLS-1$ //$NON-NLS-2$
- return Status.OK_STATUS;
- }
- }.schedule();
- }
- return Status.OK_STATUS;
- }
- }.schedule();
- }
+ return Status.OK_STATUS;
+ }
+ }.schedule();
+ }
+ return Status.OK_STATUS;
+ }
+ }.schedule();
+ }
}
private IFile getResource(PDAStackFrame frame) {
- ISourceLocator locator = frame.getLaunch().getSourceLocator();
- Object sourceElement = locator.getSourceElement(frame);
- if (sourceElement instanceof IFile) {
- return (IFile)sourceElement;
- }
- return null;
+ ISourceLocator locator = frame.getLaunch().getSourceLocator();
+ Object sourceElement = locator.getSourceElement(frame);
+ if (sourceElement instanceof IFile) {
+ return (IFile)sourceElement;
+ }
+ return null;
}
private int findLine(IFile file, String var) throws CoreException {
- int lineNum = 0;
+ int lineNum = 0;
try (BufferedReader reader = new BufferedReader(new InputStreamReader(file.getContents()))) {
- while(true) {
- String line = reader.readLine().trim();
+ while(true) {
+ String line = reader.readLine().trim();
if (line.startsWith("var")) { //$NON-NLS-1$
String varName = line.substring("var".length()).trim(); //$NON-NLS-1$
- if (varName.equals(var)) {
- break;
- }
- }
- lineNum++;
- }
- } catch (IOException e) {
- // end of file reached and line wasn't found
- return -1;
+ if (varName.equals(var)) {
+ break;
+ }
+ }
+ lineNum++;
+ }
+ } catch (IOException e) {
+ // end of file reached and line wasn't found
+ return -1;
}
return lineNum;
}
- @Override
+ @Override
public void toggleBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
- if (canToggleWatchpoints(part, selection)) {
- toggleWatchpoints(part, selection);
- } else {
- toggleLineBreakpoints(part, selection);
- }
- }
-
- @Override
+ if (canToggleWatchpoints(part, selection)) {
+ toggleWatchpoints(part, selection);
+ } else {
+ toggleLineBreakpoints(part, selection);
+ }
+ }
+
+ @Override
public boolean canToggleBreakpoints(IWorkbenchPart part, ISelection selection) {
- return canToggleLineBreakpoints(part, selection) || canToggleWatchpoints(part, selection);
- }
+ return canToggleLineBreakpoints(part, selection) || canToggleWatchpoints(part, selection);
+ }
}

Back to the top