1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-20 07:25:23 +02:00

Bug 515296: Cosmetics

Reformatted file, added missing braces and removed "non-Javadoc" comments.
This file had suffered particularly badly from mixed spaces and tabs
in a single file, with some lines having both on the same line.

Change-Id: I0bff49effa0225cb6409547d8daa9dbf9c22e1b9
This commit is contained in:
Jonah Graham 2017-04-20 15:42:45 +01:00
parent 65c9e08d68
commit 8da9b7a0b8

View file

@ -89,21 +89,22 @@ import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.ui.texteditor.ITextEditor; import org.eclipse.ui.texteditor.ITextEditor;
/** /**
* Source display adapter that performs the source lookup, opens the editor, * Source display adapter that performs the source lookup, opens the editor, and
* and paints the IP for the given object. * paints the IP for the given object.
* <p> * <p>
* The implementation relies on three types of jobs to perform the operations.<br> * The implementation relies on three types of jobs to perform the
* operations.<br>
* - The first kind, "lookup job" performs the source lookup operation. <br> * - The first kind, "lookup job" performs the source lookup operation. <br>
* - The second "display job" positions and annotates the editor. <br> * - The second "display job" positions and annotates the editor. <br>
* - The third clears the old IP annotations when a thread or process has resumed * - The third clears the old IP annotations when a thread or process has
* or exited. * resumed or exited.
* </p> * </p>
* <p> * <p>
* The the lookup jobs can run in parallel with the display or the clearing job, * The the lookup jobs can run in parallel with the display or the clearing job,
* but the clearing job and the display job must not run at the same time. * but the clearing job and the display job must not run at the same time. Hence
* Hence there is some involved logic which ensures that the jobs are run in * there is some involved logic which ensures that the jobs are run in proper
* proper order. To avoid race conditions, this logic uses the session's * order. To avoid race conditions, this logic uses the session's dispatch
* dispatch thread to synchronize access to the state data of the running jobs. * thread to synchronize access to the state data of the running jobs.
* </p> * </p>
* <p> * <p>
* Debuggers can override the default source editor used by the source display * Debuggers can override the default source editor used by the source display
@ -115,8 +116,7 @@ import org.eclipse.ui.texteditor.ITextEditor;
* @since 1.0 * @since 1.0
*/ */
@ThreadSafe @ThreadSafe
public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControlParticipant public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControlParticipant {
{
private static final class FrameData { private static final class FrameData {
IFrameDMContext fDmc; IFrameDMContext fDmc;
int fLine; int fLine;
@ -125,28 +125,36 @@ public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControl
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj) {
return true; return true;
if (obj == null) }
if (obj == null) {
return false; return false;
if (getClass() != obj.getClass()) }
if (getClass() != obj.getClass()) {
return false; return false;
}
FrameData other = (FrameData) obj; FrameData other = (FrameData) obj;
if (!fDmc.equals(other.fDmc)) if (!fDmc.equals(other.fDmc)) {
return false; return false;
}
if (fFile == null) { if (fFile == null) {
if (other.fFile != null) if (other.fFile != null) {
return false; return false;
} else if (!fFile.equals(other.fFile)) }
} else if (!fFile.equals(other.fFile)) {
return false; return false;
}
return true; return true;
} }
/** /**
* Test whether the given frame data instance refers to the very same location. * Test whether the given frame data instance refers to the very same
* location.
* *
* @param frameData * @param frameData
* @return <code>true</code> if the frame data refers to the same location * @return <code>true</code> if the frame data refers to the same
* location
*/ */
public boolean isIdentical(FrameData frameData) { public boolean isIdentical(FrameData frameData) {
return equals(frameData) && fLine == frameData.fLine; return equals(frameData) && fLine == frameData.fLine;
@ -174,7 +182,9 @@ public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControl
fEventTriggered = eventTriggered; fEventTriggered = eventTriggered;
} }
IDMContext getDmc() { return fFrameData.fDmc; } IDMContext getDmc() {
return fFrameData.fDmc;
}
@Override @Override
protected IStatus run(final IProgressMonitor monitor) { protected IStatus run(final IProgressMonitor monitor) {
@ -183,7 +193,8 @@ public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControl
} }
final SourceLookupResult result = performLookup(); final SourceLookupResult result = performLookup();
executeFromJob(new DsfRunnable() { @Override executeFromJob(new DsfRunnable() {
@Override
public void run() { public void run() {
if (!monitor.isCanceled()) { if (!monitor.isCanceled()) {
fPrevResult = result; fPrevResult = result;
@ -191,22 +202,24 @@ public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControl
fRunningLookupJob = null; fRunningLookupJob = null;
startDisplayJob(fPrevResult, fFrameData, fPage, fEventTriggered); startDisplayJob(fPrevResult, fFrameData, fPage, fEventTriggered);
} }
}}); }
});
return Status.OK_STATUS; return Status.OK_STATUS;
} }
private SourceLookupResult performLookup() { private SourceLookupResult performLookup() {
IDMContext dmc = fFrameData.fDmc; IDMContext dmc = fFrameData.fDmc;
SourceLookupResult result = new SourceLookupResult(dmc , null, null, null); SourceLookupResult result = new SourceLookupResult(dmc, null, null, null);
String editorId = null; String editorId = null;
IEditorInput editorInput = null; IEditorInput editorInput = null;
Object sourceElement = fSourceLookup.getSourceElement(dmc); Object sourceElement = fSourceLookup.getSourceElement(dmc);
if (sourceElement == null) { if (sourceElement == null) {
editorInput = new CSourceNotFoundEditorInput(new CSourceNotFoundElement(dmc, fSourceLookup.getLaunchConfiguration(), fFrameData.fFile)); editorInput = new CSourceNotFoundEditorInput(
new CSourceNotFoundElement(dmc, fSourceLookup.getLaunchConfiguration(), fFrameData.fFile));
editorId = ICDebugUIConstants.CSOURCENOTFOUND_EDITOR_ID; editorId = ICDebugUIConstants.CSOURCENOTFOUND_EDITOR_ID;
} else { } else {
ISourcePresentation presentation= null; ISourcePresentation presentation = null;
if (fSourceLookup instanceof ISourcePresentation) { if (fSourceLookup instanceof ISourcePresentation) {
presentation = (ISourcePresentation) fSourceLookup; presentation = (ISourcePresentation) fSourceLookup;
} else { } else {
@ -220,20 +233,21 @@ public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControl
editorId = presentation.getEditorId(editorInput, sourceElement); editorId = presentation.getEditorId(editorInput, sourceElement);
} }
} else if (sourceElement instanceof IFile) { } else if (sourceElement instanceof IFile) {
editorId = getEditorIdForFilename(((IFile)sourceElement).getName()); editorId = getEditorIdForFilename(((IFile) sourceElement).getName());
editorInput = new FileEditorInput((IFile)sourceElement); editorInput = new FileEditorInput((IFile) sourceElement);
} else if (sourceElement instanceof ITranslationUnit) { } else if (sourceElement instanceof ITranslationUnit) {
try { try {
URI uriLocation = ((ITranslationUnit)sourceElement).getLocationURI(); URI uriLocation = ((ITranslationUnit) sourceElement).getLocationURI();
IFileStore fileStore = EFS.getStore(uriLocation); IFileStore fileStore = EFS.getStore(uriLocation);
editorInput = new FileStoreEditorInput(fileStore); editorInput = new FileStoreEditorInput(fileStore);
editorId = getEditorIdForFilename(fileStore.getName()); editorId = getEditorIdForFilename(fileStore.getName());
} catch (CoreException e) { } catch (CoreException e) {
editorInput = new CSourceNotFoundEditorInput(new CSourceNotFoundElement(dmc, fSourceLookup.getLaunchConfiguration(), fFrameData.fFile)); editorInput = new CSourceNotFoundEditorInput(new CSourceNotFoundElement(dmc,
fSourceLookup.getLaunchConfiguration(), fFrameData.fFile));
editorId = ICDebugUIConstants.CSOURCENOTFOUND_EDITOR_ID; editorId = ICDebugUIConstants.CSOURCENOTFOUND_EDITOR_ID;
} }
} else if (sourceElement instanceof LocalFileStorage) { } else if (sourceElement instanceof LocalFileStorage) {
File file = ((LocalFileStorage)sourceElement).getFile(); File file = ((LocalFileStorage) sourceElement).getFile();
IFileStore fileStore = EFS.getLocalFileSystem().fromLocalFile(file); IFileStore fileStore = EFS.getLocalFileSystem().fromLocalFile(file);
editorInput = new FileStoreEditorInput(fileStore); editorInput = new FileStoreEditorInput(fileStore);
editorId = getEditorIdForFilename(file.getName()); editorId = getEditorIdForFilename(file.getName());
@ -248,7 +262,7 @@ public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControl
private String getEditorIdForFilename(String filename) { private String getEditorIdForFilename(String filename) {
try { try {
IEditorDescriptor descriptor= IDE.getEditorDescriptor(filename); IEditorDescriptor descriptor = IDE.getEditorDescriptor(filename);
return descriptor.getId(); return descriptor.getId();
} catch (PartInitException exc) { } catch (PartInitException exc) {
DsfUIPlugin.log(exc); DsfUIPlugin.log(exc);
@ -268,8 +282,11 @@ public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControl
private final DsfRunnable fDisplayJobFinishedRunnable = new DsfRunnable() { private final DsfRunnable fDisplayJobFinishedRunnable = new DsfRunnable() {
@Override @Override
public void run() { public void run() {
// If the current display job does not match up with "this", it means that this job got canceled /*
// after it already completed and after this runnable was queued into the dispatch thread. * If the current display job does not match up with "this", it
* means that this job got canceled after it already completed
* and after this runnable was queued into the dispatch thread.
*/
if (fRunningDisplayJob == DisplayJob.this) { if (fRunningDisplayJob == DisplayJob.this) {
fRunningDisplayJob = null; fRunningDisplayJob = null;
if (fEventTriggered && !fDoneStepping.getAndSet(true)) { if (fEventTriggered && !fDoneStepping.getAndSet(true)) {
@ -285,7 +302,9 @@ public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControl
private ITextViewer fTextViewer; private ITextViewer fTextViewer;
private final boolean fEventTriggered; private final boolean fEventTriggered;
IDMContext getDmc() { return fResult.getDmc(); } IDMContext getDmc() {
return fResult.getDmc();
}
/** /**
* Constructs a new source display job * Constructs a new source display job
@ -325,7 +344,7 @@ public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControl
ITextEditor textEditor = null; ITextEditor textEditor = null;
if (editor instanceof ITextEditor) { if (editor instanceof ITextEditor) {
textEditor = (ITextEditor)editor; textEditor = (ITextEditor) editor;
} else { } else {
textEditor = editor.getAdapter(ITextEditor.class); textEditor = editor.getAdapter(ITextEditor.class);
} }
@ -370,13 +389,13 @@ public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControl
} }
/** /**
* Opens the editor used to display the source for an element selected in * Opens the editor used to display the source for an element selected
* this view and returns the editor that was opened or <code>null</code> if * in this view and returns the editor that was opened or
* no editor could be opened. * <code>null</code> if no editor could be opened.
*/ */
private IEditorPart openEditor(SourceLookupResult result, IWorkbenchPage page) { private IEditorPart openEditor(SourceLookupResult result, IWorkbenchPage page) {
IEditorInput input= result.getEditorInput(); IEditorInput input = result.getEditorInput();
String id= result.getEditorId(); String id = result.getEditorId();
if (input == null || id == null) { if (input == null || id == null) {
return null; return null;
} }
@ -385,30 +404,34 @@ public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControl
} }
/** /**
* Opens an editor in the workbench and returns the editor that was opened * Opens an editor in the workbench and returns the editor that was
* or <code>null</code> if an error occurred while attempting to open the * opened or <code>null</code> if an error occurred while attempting to
* editor. * open the editor.
*/ */
private IEditorPart openEditor(final IWorkbenchPage page, final IEditorInput input, final String id) { private IEditorPart openEditor(final IWorkbenchPage page, final IEditorInput input, final String id) {
final IEditorPart[] editor = new IEditorPart[] {null}; final IEditorPart[] editor = new IEditorPart[] { null };
Runnable r = new Runnable() { Runnable r = new Runnable() {
@Override @Override
public void run() { public void run() {
if (!page.getWorkbenchWindow().getWorkbench().isClosing()) { if (!page.getWorkbenchWindow().getWorkbench().isClosing()) {
try { try {
if (input instanceof CSourceNotFoundEditorInput) if (input instanceof CSourceNotFoundEditorInput) {
{ // Don't open additional source not found editors if /*
// there is one to reuse. * Don't open additional source not found
* editors if there is one to reuse.
*/
editor[0] = page.openEditor(input, id, false, IWorkbenchPage.MATCH_ID); editor[0] = page.openEditor(input, id, false, IWorkbenchPage.MATCH_ID);
if (editor[0] instanceof IReusableEditor) { if (editor[0] instanceof IReusableEditor) {
IReusableEditor re = (IReusableEditor)editor[0]; IReusableEditor re = (IReusableEditor) editor[0];
if (! input.equals(re.getEditorInput())) if (!input.equals(re.getEditorInput())) {
re.setInput(input); re.setInput(input);
} }
} }
else } else {
editor[0] = page.openEditor(input, id, false); editor[0] = page.openEditor(input, id, false);
} catch (PartInitException e) {} }
} catch (PartInitException e) {
}
} }
} }
}; };
@ -421,17 +444,17 @@ public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControl
*/ */
private boolean positionEditor(ITextEditor editor, final FrameData frameData) { private boolean positionEditor(ITextEditor editor, final FrameData frameData) {
// Position and annotate the editor. // Position and annotate the editor.
fRegion= getLineInformation(editor, frameData.fLine); fRegion = getLineInformation(editor, frameData.fLine);
if (fRegion != null) { if (fRegion != null) {
// add annotation // add annotation
fIPManager.addAnnotation( fIPManager.addAnnotation(editor, frameData.fDmc, new Position(fRegion.getOffset(), fRegion.getLength()),
editor, frameData.fDmc, new Position(fRegion.getOffset(), fRegion.getLength()),
frameData.fLevel == 0); frameData.fLevel == 0);
// this is a dirty trick to get access to the ITextViewer of the editor // this is a dirty trick to get access to the ITextViewer of the
// editor
Object tot = editor.getAdapter(ITextOperationTarget.class); Object tot = editor.getAdapter(ITextOperationTarget.class);
if (tot instanceof ITextViewer) { if (tot instanceof ITextViewer) {
fTextViewer = (ITextViewer)tot; fTextViewer = (ITextViewer) tot;
int widgetLine = frameData.fLine; int widgetLine = frameData.fLine;
if (tot instanceof ITextViewerExtension5) { if (tot instanceof ITextViewerExtension5) {
ITextViewerExtension5 ext5 = (ITextViewerExtension5) tot; ITextViewerExtension5 ext5 = (ITextViewerExtension5) tot;
@ -462,6 +485,7 @@ public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControl
/** /**
* Scroll the given line into the visible area if it is not yet visible. * Scroll the given line into the visible area if it is not yet visible.
*
* @param focusLine * @param focusLine
* @see org.eclipse.jface.text.TextViewer#revealRange(int, int) * @see org.eclipse.jface.text.TextViewer#revealRange(int, int)
*/ */
@ -481,7 +505,8 @@ public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControl
} else { } else {
if (focusLine > bottom - bottomBuffer && focusLine <= bottom) { if (focusLine > bottom - bottomBuffer && focusLine <= bottom) {
// focusLine is already in bottom bufferZone // focusLine is already in bottom bufferZone
// scroll to top of bottom bufferzone - for smooth down-scrolling // scroll to top of bottom bufferzone - for smooth
// down-scrolling
int scrollDelta = focusLine - (bottom - bottomBuffer); int scrollDelta = focusLine - (bottom - bottomBuffer);
textWidget.setTopIndex(top + scrollDelta); textWidget.setTopIndex(top + scrollDelta);
} else { } else {
@ -494,15 +519,16 @@ public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControl
} }
/** /**
* @return the number of visible lines in the view port assuming a constant * @return the number of visible lines in the view port assuming a
* line height. * constant line height.
*/ */
private int getEstimatedVisibleLinesInViewport(StyledText textWidget) { private int getEstimatedVisibleLinesInViewport(StyledText textWidget) {
if (textWidget != null) { if (textWidget != null) {
Rectangle clArea= textWidget.getClientArea(); Rectangle clArea = textWidget.getClientArea();
if (!clArea.isEmpty()) if (!clArea.isEmpty()) {
return clArea.height / textWidget.getLineHeight(); return clArea.height / textWidget.getLineHeight();
} }
}
return -1; return -1;
} }
@ -510,17 +536,18 @@ public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControl
* Returns the line information for the given line in the given editor * Returns the line information for the given line in the given editor
*/ */
private IRegion getLineInformation(ITextEditor editor, int lineNumber) { private IRegion getLineInformation(ITextEditor editor, int lineNumber) {
IDocumentProvider provider= editor.getDocumentProvider(); IDocumentProvider provider = editor.getDocumentProvider();
IEditorInput input= editor.getEditorInput(); IEditorInput input = editor.getEditorInput();
try { try {
provider.connect(input); provider.connect(input);
} catch (CoreException e) { } catch (CoreException e) {
return null; return null;
} }
try { try {
IDocument document= provider.getDocument(input); IDocument document = provider.getDocument(input);
if (document != null) if (document != null) {
return document.getLineInformation(lineNumber); return document.getLineInformation(lineNumber);
}
} catch (BadLocationException e) { } catch (BadLocationException e) {
} finally { } finally {
provider.disconnect(input); provider.disconnect(input);
@ -544,17 +571,16 @@ public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControl
fDmcsToClear = dmcs; fDmcsToClear = dmcs;
} }
/* (non-Javadoc)
* @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor)
*/
@Override @Override
public IStatus runInUIThread(IProgressMonitor monitor) { public IStatus runInUIThread(IProgressMonitor monitor) {
DsfRunnable clearingJobFinishedRunnable = new DsfRunnable() { @Override DsfRunnable clearingJobFinishedRunnable = new DsfRunnable() {
@Override
public void run() { public void run() {
assert fRunningClearingJob == ClearingJob.this; assert fRunningClearingJob == ClearingJob.this;
fRunningClearingJob = null; fRunningClearingJob = null;
serviceDisplayAndClearingJobs(); serviceDisplayAndClearingJobs();
}}; }
};
enableLineBackgroundPainter(); enableLineBackgroundPainter();
@ -590,7 +616,10 @@ public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControl
private Set<IRunControl.IExecutionDMContext> fPendingExecDmcsToClear = new HashSet<IRunControl.IExecutionDMContext>(); private Set<IRunControl.IExecutionDMContext> fPendingExecDmcsToClear = new HashSet<IRunControl.IExecutionDMContext>();
private SteppingController fController; private SteppingController fController;
/** Delay (in milliseconds) before the selection is changed to the IP location */ /**
* Delay (in milliseconds) before the selection is changed to the IP
* location
*/
private int fSelectionChangeDelay = 150; private int fSelectionChangeDelay = 150;
private long fStepStartTime = 0; private long fStepStartTime = 0;
@ -606,21 +635,25 @@ public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControl
/** /**
* @since 1.1 * @since 1.1
*/ */
public DsfSourceDisplayAdapter(DsfSession session, ISourceLookupDirector sourceLocator, SteppingController controller) { public DsfSourceDisplayAdapter(DsfSession session, ISourceLookupDirector sourceLocator,
SteppingController controller) {
fSession = session; fSession = session;
fExecutor = session.getExecutor(); fExecutor = session.getExecutor();
fServicesTracker = new DsfServicesTracker(DsfUIPlugin.getBundleContext(), session.getId()); fServicesTracker = new DsfServicesTracker(DsfUIPlugin.getBundleContext(), session.getId());
fSourceLookup = sourceLocator; fSourceLookup = sourceLocator;
fSourceLookupParticipant = new DsfSourceLookupParticipant(session); fSourceLookupParticipant = new DsfSourceLookupParticipant(session);
fSourceLookup.addParticipants(new ISourceLookupParticipant[] {fSourceLookupParticipant} ); fSourceLookup.addParticipants(new ISourceLookupParticipant[] { fSourceLookupParticipant });
final IInstructionPointerPresentation ipPresentation = (IInstructionPointerPresentation) session.getModelAdapter(IInstructionPointerPresentation.class); final IInstructionPointerPresentation ipPresentation = (IInstructionPointerPresentation) session
.getModelAdapter(IInstructionPointerPresentation.class);
fIPManager = new InstructionPointerManager(ipPresentation); fIPManager = new InstructionPointerManager(ipPresentation);
fExecutor.execute(new DsfRunnable() { @Override fExecutor.execute(new DsfRunnable() {
@Override
public void run() { public void run() {
fSession.addServiceEventListener(DsfSourceDisplayAdapter.this, null); fSession.addServiceEventListener(DsfSourceDisplayAdapter.this, null);
}}); }
});
fController = controller; fController = controller;
if (fController != null) { if (fController != null) {
@ -632,7 +665,8 @@ public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControl
* Configure the delay (in milliseconds) before the selection in the editor * Configure the delay (in milliseconds) before the selection in the editor
* is changed to the IP location. * is changed to the IP location.
* *
* @param delay the delay in milliseconds, a non-negative integer * @param delay
* the delay in milliseconds, a non-negative integer
* *
* @since 1.1 * @since 1.1
*/ */
@ -647,16 +681,18 @@ public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControl
} }
try { try {
fExecutor.execute(new DsfRunnable() { @Override fExecutor.execute(new DsfRunnable() {
@Override
public void run() { public void run() {
fSession.removeServiceEventListener(DsfSourceDisplayAdapter.this); fSession.removeServiceEventListener(DsfSourceDisplayAdapter.this);
}}); }
});
} catch (RejectedExecutionException e) { } catch (RejectedExecutionException e) {
// Session is shut down. // Session is shut down.
} }
fServicesTracker.dispose(); fServicesTracker.dispose();
fSourceLookup.removeParticipants(new ISourceLookupParticipant[] {fSourceLookupParticipant}); fSourceLookup.removeParticipants(new ISourceLookupParticipant[] { fSourceLookupParticipant });
// fSourceLookupParticipant is disposed by the source lookup director // fSourceLookupParticipant is disposed by the source lookup director
@ -668,54 +704,59 @@ public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControl
public void run() { public void run() {
enableLineBackgroundPainter(); enableLineBackgroundPainter();
fIPManager.removeAllAnnotations(); fIPManager.removeAllAnnotations();
}}); }
});
} }
} }
/* (non-Javadoc)
* @see org.eclipse.debug.ui.contexts.ISourceDisplayAdapter#displaySource(java.lang.Object, org.eclipse.ui.IWorkbenchPage, boolean)
*/
@Override @Override
public void displaySource(Object context, final IWorkbenchPage page, public void displaySource(Object context, final IWorkbenchPage page, final boolean force) {
final boolean force) {
fStepCount = 0; fStepCount = 0;
IFrameDMContext displayFrame = null; IFrameDMContext displayFrame = null;
if (context instanceof IDMVMContext) { if (context instanceof IDMVMContext) {
IDMContext dmc = ((IDMVMContext) context).getDMContext(); IDMContext dmc = ((IDMVMContext) context).getDMContext();
if (dmc instanceof IFrameDMContext) if (dmc instanceof IFrameDMContext) {
displayFrame = (IFrameDMContext) dmc; displayFrame = (IFrameDMContext) dmc;
} else if (context instanceof IFrameDMContext) }
} else if (context instanceof IFrameDMContext) {
displayFrame = (IFrameDMContext) context; displayFrame = (IFrameDMContext) context;
}
// Quick test. DMC is checked again in source lookup participant, but // Quick test. DMC is checked again in source lookup participant, but
// it's much quicker to test here. // it's much quicker to test here.
if (displayFrame != null) if (displayFrame != null) {
doDisplaySource(displayFrame, page, force, false); doDisplaySource(displayFrame, page, force, false);
} }
}
private void doDisplaySource(final IFrameDMContext context, final IWorkbenchPage page, final boolean force, final boolean eventTriggered) { private void doDisplaySource(final IFrameDMContext context, final IWorkbenchPage page, final boolean force,
if (DEBUG) System.out.println("[DsfSourceDisplayAdapter] doDisplaySource ctx="+context+" eventTriggered="+eventTriggered); //$NON-NLS-1$ //$NON-NLS-2$ final boolean eventTriggered) {
if (DEBUG) {
System.out.println(
"[DsfSourceDisplayAdapter] doDisplaySource ctx=" + context + " eventTriggered=" + eventTriggered); //$NON-NLS-1$ //$NON-NLS-2$
}
if (context.getLevel() < 0) { if (context.getLevel() < 0) {
return; return;
} }
// Re-dispatch to executor thread before accessing job lists. // Re-dispatch to executor thread before accessing job lists.
fExecutor.execute(new DsfRunnable() { @Override fExecutor.execute(new DsfRunnable() {
@Override
public void run() { public void run() {
// We need to retrieve the frame level and line number from the service. // We need to retrieve the frame level and line number from the
// service.
IStack stackService = fServicesTracker.getService(IStack.class); IStack stackService = fServicesTracker.getService(IStack.class);
if (stackService == null) { if (stackService == null) {
return; return;
} }
stackService.getFrameData( stackService.getFrameData(context, new DataRequestMonitor<IFrameDMData>(fExecutor, null) {
context,
new DataRequestMonitor<IFrameDMData>(fExecutor, null) {
@Override @Override
public void handleSuccess() { public void handleSuccess() {
FrameData frameData = new FrameData(); FrameData frameData = new FrameData();
frameData.fDmc = context; frameData.fDmc = context;
frameData.fLevel = context.getLevel(); frameData.fLevel = context.getLevel();
// Document line numbers are 0-based. While debugger line numbers are 1-based. // Document line numbers are 0-based. While debugger
// line numbers are 1-based.
IFrameDMData data = getData(); IFrameDMData data = getData();
frameData.fLine = data.getLine() - 1; frameData.fLine = data.getLine() - 1;
frameData.fFile = data.getFile(); frameData.fFile = data.getFile();
@ -726,6 +767,7 @@ public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControl
startLookupJob(frameData, page, eventTriggered); startLookupJob(frameData, page, eventTriggered);
} }
} }
@Override @Override
protected void handleFailure() { protected void handleFailure() {
doneStepping(context); doneStepping(context);
@ -736,7 +778,8 @@ public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControl
doneStepping(context); doneStepping(context);
} }
}); });
}}); }
});
} }
private void executeFromJob(Runnable runnable) { private void executeFromJob(Runnable runnable) {
@ -756,9 +799,11 @@ public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControl
} }
// cancel running lookup job // cancel running lookup job
fRunningLookupJob.cancel(); fRunningLookupJob.cancel();
// make sure doneStepping() is called even if the job never ran - bug 325394 // make sure doneStepping() is called even if the job never ran -
// bug 325394
if (fRunningLookupJob.fEventTriggered) { if (fRunningLookupJob.fEventTriggered) {
// ... but not if this request is event-triggered for the same context (duplicate suspended event) // ... but not if this request is event-triggered for the same
// context (duplicate suspended event)
if (!eventTriggered || !fRunningLookupJob.getDmc().equals(frameData.fDmc)) { if (!eventTriggered || !fRunningLookupJob.getDmc().equals(frameData.fDmc)) {
doneStepping(fRunningLookupJob.getDmc()); doneStepping(fRunningLookupJob.getDmc());
} }
@ -770,11 +815,13 @@ public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControl
} }
// To be called only on dispatch thread. // To be called only on dispatch thread.
private void startDisplayJob(SourceLookupResult lookupResult, FrameData frameData, IWorkbenchPage page, boolean eventTriggered) { private void startDisplayJob(SourceLookupResult lookupResult, FrameData frameData, IWorkbenchPage page,
boolean eventTriggered) {
DisplayJob nextDisplayJob = new DisplayJob(lookupResult, frameData, page, eventTriggered); DisplayJob nextDisplayJob = new DisplayJob(lookupResult, frameData, page, eventTriggered);
if (fRunningDisplayJob != null) { if (fRunningDisplayJob != null) {
fPendingDisplayJob = null; fPendingDisplayJob = null;
IExecutionDMContext[] execCtxs = DMContexts.getAllAncestorsOfType(frameData.fDmc, IExecutionDMContext.class); IExecutionDMContext[] execCtxs = DMContexts.getAllAncestorsOfType(frameData.fDmc,
IExecutionDMContext.class);
fPendingExecDmcsToClear.removeAll(Arrays.asList(execCtxs)); fPendingExecDmcsToClear.removeAll(Arrays.asList(execCtxs));
if (!eventTriggered && frameData.isIdentical(fRunningDisplayJob.fFrameData)) { if (!eventTriggered && frameData.isIdentical(fRunningDisplayJob.fFrameData)) {
@ -783,9 +830,11 @@ public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControl
} }
// cancel running display job // cancel running display job
fRunningDisplayJob.cancel(); fRunningDisplayJob.cancel();
// make sure doneStepping() is called even if the job never ran - bug 325394 // make sure doneStepping() is called even if the job never ran -
// bug 325394
if (fRunningDisplayJob.fEventTriggered && !fRunningDisplayJob.fDoneStepping.getAndSet(true)) { if (fRunningDisplayJob.fEventTriggered && !fRunningDisplayJob.fDoneStepping.getAndSet(true)) {
// ... but not if this request is event-triggered for the same context (duplicate suspended event) // ... but not if this request is event-triggered for the same
// context (duplicate suspended event)
if (!eventTriggered || !fRunningDisplayJob.getDmc().equals(lookupResult.getDmc())) { if (!eventTriggered || !fRunningDisplayJob.getDmc().equals(lookupResult.getDmc())) {
doneStepping(fRunningDisplayJob.getDmc()); doneStepping(fRunningDisplayJob.getDmc());
} }
@ -854,7 +903,8 @@ public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControl
} }
} }
// If no display or clearing jobs are running, schedule the clearing job. // If no display or clearing jobs are running, schedule the clearing
// job.
if (fRunningClearingJob == null && fRunningDisplayJob == null) { if (fRunningClearingJob == null && fRunningDisplayJob == null) {
fRunningClearingJob = new ClearingJob(fPendingExecDmcsToClear); fRunningClearingJob = new ClearingJob(fPendingExecDmcsToClear);
fRunningClearingJob.schedule(); fRunningClearingJob.schedule();
@ -886,14 +936,16 @@ public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControl
public void eventDispatched(final IRunControl.ISuspendedDMEvent e) { public void eventDispatched(final IRunControl.ISuspendedDMEvent e) {
updateStepTiming(); updateStepTiming();
if (e.getReason() == StateChangeReason.STEP || e.getReason() == StateChangeReason.BREAKPOINT) { if (e.getReason() == StateChangeReason.STEP || e.getReason() == StateChangeReason.BREAKPOINT) {
if (DEBUG) System.out.println("[DsfSourceDisplayAdapter] eventDispatched e="+e); //$NON-NLS-1$ if (DEBUG) {
System.out.println("[DsfSourceDisplayAdapter] eventDispatched e=" + e); //$NON-NLS-1$
}
// trigger source display immediately (should be optional?) // trigger source display immediately (should be optional?)
Display.getDefault().asyncExec(new Runnable() { Display.getDefault().asyncExec(new Runnable() {
@Override @Override
public void run() { public void run() {
Object context = DebugUITools.getDebugContext(); Object context = DebugUITools.getDebugContext();
if (context instanceof IDMVMContext) { if (context instanceof IDMVMContext) {
final IDMContext dmc = ((IDMVMContext)context).getDMContext(); final IDMContext dmc = ((IDMVMContext) context).getDMContext();
if (dmc instanceof IFrameDMContext && DMContexts.isAncestorOf(dmc, e.getDMContext())) { if (dmc instanceof IFrameDMContext && DMContexts.isAncestorOf(dmc, e.getDMContext())) {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
doDisplaySource((IFrameDMContext) dmc, page, false, true); doDisplaySource((IFrameDMContext) dmc, page, false, true);
@ -901,7 +953,8 @@ public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControl
} }
} }
doneStepping(e.getDMContext()); doneStepping(e.getDMContext());
}}); }
});
} else { } else {
doneStepping(e.getDMContext()); doneStepping(e.getDMContext());
} }
@ -918,8 +971,8 @@ public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControl
++fStepCount; ++fStepCount;
if (DEBUG) { if (DEBUG) {
long delta = now - fStepStartTime; long delta = now - fStepStartTime;
float meanTime = delta/(float)fStepCount/1000; float meanTime = delta / (float) fStepCount / 1000;
System.out.println("[DsfSourceDisplayAdapter] step speed = " + 1/meanTime); //$NON-NLS-1$ System.out.println("[DsfSourceDisplayAdapter] step speed = " + 1 / meanTime); //$NON-NLS-1$
} }
} }
@ -931,9 +984,11 @@ public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControl
*/ */
private void disableLineBackgroundPainter() { private void disableLineBackgroundPainter() {
if (!fEnableLineBackgroundPainter) { if (!fEnableLineBackgroundPainter) {
fEnableLineBackgroundPainter = EditorsUI.getPreferenceStore().getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE); fEnableLineBackgroundPainter = EditorsUI.getPreferenceStore()
.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE);
if (fEnableLineBackgroundPainter) { if (fEnableLineBackgroundPainter) {
EditorsUI.getPreferenceStore().setValue(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE, false); EditorsUI.getPreferenceStore()
.setValue(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE, false);
} }
} }
} }
@ -947,7 +1002,8 @@ public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControl
private void enableLineBackgroundPainter() { private void enableLineBackgroundPainter() {
if (fEnableLineBackgroundPainter) { if (fEnableLineBackgroundPainter) {
fEnableLineBackgroundPainter = false; fEnableLineBackgroundPainter = false;
EditorsUI.getPreferenceStore().setValue(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE, true); EditorsUI.getPreferenceStore().setValue(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE,
true);
} }
} }