diff options
author | Mike Rennie | 2014-08-13 12:51:53 +0000 |
---|---|---|
committer | Mike Rennie | 2014-08-13 12:52:34 +0000 |
commit | bbfb01305dca3332c80e5cdc4a50b5b7ddcbdf31 (patch) | |
tree | 7a9a96383569e0ee6cef97d71db669cdd9498beb | |
parent | 5d4ea367b42aa3d2a875fcc86f4ccf6ef74a62fe (diff) | |
download | eclipse.platform.debug-bbfb01305dca3332c80e5cdc4a50b5b7ddcbdf31.tar.gz eclipse.platform.debug-bbfb01305dca3332c80e5cdc4a50b5b7ddcbdf31.tar.xz eclipse.platform.debug-bbfb01305dca3332c80e5cdc4a50b5b7ddcbdf31.zip |
Bug 437193 - JSR-45 Support broken
11 files changed, 602 insertions, 309 deletions
diff --git a/org.eclipse.debug.tests/META-INF/MANIFEST.MF b/org.eclipse.debug.tests/META-INF/MANIFEST.MF index ee106f378..a7168199b 100644 --- a/org.eclipse.debug.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.debug.tests/META-INF/MANIFEST.MF @@ -20,6 +20,7 @@ Export-Package: org.eclipse.debug.tests, org.eclipse.debug.tests.breakpoint, org.eclipse.debug.tests.expressions, org.eclipse.debug.tests.launching, + org.eclipse.debug.tests.sourcelookup, org.eclipse.debug.tests.statushandlers, org.eclipse.debug.tests.stepfilters, org.eclipse.debug.tests.view.memory, diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/AutomatedSuite.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/AutomatedSuite.java index b268324ac..7af33159d 100644 --- a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/AutomatedSuite.java +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/AutomatedSuite.java @@ -23,6 +23,7 @@ import org.eclipse.debug.tests.launching.LaunchFavoriteTests; import org.eclipse.debug.tests.launching.LaunchHistoryTests; import org.eclipse.debug.tests.launching.LaunchManagerTests; import org.eclipse.debug.tests.launching.RefreshTabTests; +import org.eclipse.debug.tests.sourcelookup.SourceLookupFacilityTests; import org.eclipse.debug.tests.statushandlers.StatusHandlerTests; import org.eclipse.debug.tests.stepfilters.StepFiltersTests; import org.eclipse.debug.tests.view.memory.MemoryRenderingTests; @@ -57,6 +58,9 @@ public class AutomatedSuite extends TestSuite { * Constructs the automated test suite. Adds all tests. */ public AutomatedSuite() { + // Source lookup tests + addTest(new TestSuite(SourceLookupFacilityTests.class)); + // BP tests addTest(new TestSuite(BreakpointOrderingTests.class)); // Note: jface viewer tests were moved out of nightly tests // due to frequent problems on nightly build machines. diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/sourcelookup/SourceLookupFacilityTests.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/sourcelookup/SourceLookupFacilityTests.java new file mode 100644 index 000000000..9e474edd1 --- /dev/null +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/sourcelookup/SourceLookupFacilityTests.java @@ -0,0 +1,292 @@ +/******************************************************************************* + * Copyright (c) Jul 30, 2014 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.tests.sourcelookup; + +import junit.framework.TestCase; + +import org.eclipse.debug.core.model.IStackFrame; +import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupFacility; +import org.eclipse.debug.ui.sourcelookup.ISourceLookupResult; + +/** + * Tests {@link SourceLookupFacility} + * + * @since 3.9.200 + */ +public class SourceLookupFacilityTests extends TestCase { + + /** + * {@link IStackFrame} to be reused + */ + TestStackFrame fReusableFrame = new TestStackFrame(new TestLaunch()); + /** + * Testing source director + */ + TestSourceDirector fTestDirector = new TestSourceDirector(); + /** + * Test source locator + */ + TestSourceLocator fTestLocator = new TestSourceLocator(); + + /** + * @param name + */ + public SourceLookupFacilityTests(String name) { + super(name); + } + + /** + * Tests calling + * {@link SourceLookupFacility#lookup(Object, org.eclipse.debug.core.model.ISourceLocator, boolean)} + * with simple type, no locator and no forcing + * + * @throws Exception + */ + public void testLookupStringNoLocatorNoForce() throws Exception { + try { + String artifact = "Empty"; //$NON-NLS-1$ + ISourceLookupResult result = SourceLookupFacility.getDefault().lookup(artifact, null, false); + assertNotNull("There should be a result", result); //$NON-NLS-1$ + assertNull("Source element should be null", result.getSourceElement()); //$NON-NLS-1$ + } finally { + SourceLookupFacility.shutdown(); + } + } + + /** + * Tests calling + * {@link SourceLookupFacility#lookup(Object, org.eclipse.debug.core.model.ISourceLocator, boolean)} + * with simple type and no forcing + * + * @throws Exception + */ + public void testLookupStringNoForce() throws Exception { + try { + String artifact = "One"; //$NON-NLS-1$ + ISourceLookupResult result = SourceLookupFacility.getDefault().lookup(artifact, fTestDirector, false); + assertNotNull("There should be a result", result); //$NON-NLS-1$ + assertTrue("The result artifact should be a String", result.getArtifact() instanceof String); //$NON-NLS-1$ + assertTrue("The result source element should be a String", result.getSourceElement() instanceof String); //$NON-NLS-1$ + String value = (String) result.getSourceElement(); + result = SourceLookupFacility.getDefault().lookup(artifact, fTestDirector, false); + assertNotNull("There should be a result", result); //$NON-NLS-1$ + assertTrue("The result artifact should be a String", result.getArtifact() instanceof String); //$NON-NLS-1$ + assertTrue("The result source element should be a String", result.getSourceElement() instanceof String); //$NON-NLS-1$ + assertEquals("The results should be equal", value, result.getSourceElement()); //$NON-NLS-1$ + } finally { + SourceLookupFacility.shutdown(); + } + } + + /** + * Tests calling + * {@link SourceLookupFacility#lookup(Object, org.eclipse.debug.core.model.ISourceLocator, boolean)} + * with simple type and forcing + * + * @throws Exception + */ + public void testLookupStringForce() throws Exception { + try { + String artifact = "Two"; //$NON-NLS-1$ + ISourceLookupResult result = SourceLookupFacility.getDefault().lookup(artifact, fTestDirector, true); + assertNotNull("There should be a result", result); //$NON-NLS-1$ + assertTrue("The result artifact should be a String", result.getArtifact() instanceof String); //$NON-NLS-1$ + assertTrue("The result source element should be a String", result.getSourceElement() instanceof String); //$NON-NLS-1$ + String value = (String) result.getSourceElement(); + result = SourceLookupFacility.getDefault().lookup(artifact, fTestDirector, true); + assertNotNull("There should be a result", result); //$NON-NLS-1$ + assertTrue("The result artifact should be a String", result.getArtifact() instanceof String); //$NON-NLS-1$ + assertTrue("The result source element should be a String", result.getSourceElement() instanceof String); //$NON-NLS-1$ + assertNotSame("The results should not be equal", value, result.getSourceElement()); //$NON-NLS-1$ + } finally { + SourceLookupFacility.shutdown(); + } + } + + /** + * Tests calling + * {@link SourceLookupFacility#lookup(Object, org.eclipse.debug.core.model.ISourceLocator, boolean)} + * with simple type and no forcing + * + * @throws Exception + */ + public void testLookupStringLocatorNoForce() throws Exception { + try { + String artifact = "Three"; //$NON-NLS-1$ + ISourceLookupResult result = SourceLookupFacility.getDefault().lookup(artifact, fTestLocator, false); + assertNotNull("There should be a result", result); //$NON-NLS-1$ + assertNull("The source element should be null", result.getSourceElement()); //$NON-NLS-1$ + } finally { + SourceLookupFacility.shutdown(); + } + } + + /** + * Tests calling + * {@link SourceLookupFacility#lookup(Object, org.eclipse.debug.core.model.ISourceLocator, boolean)} + * with an {@link IStackFrame} impl and no forcing + * + * @throws Exception + */ + public void testLookupStackframeNoForce() throws Exception { + try { + ISourceLookupResult result = SourceLookupFacility.getDefault().lookup(fReusableFrame, fTestDirector, false); + assertNotNull("There should be a result", result); //$NON-NLS-1$ + assertTrue("The result source element should be a String", result.getArtifact() instanceof IStackFrame); //$NON-NLS-1$ + assertTrue("The result source element should be a String", result.getSourceElement() instanceof String); //$NON-NLS-1$ + String value = (String) result.getSourceElement(); + result = SourceLookupFacility.getDefault().lookup(fReusableFrame, fTestDirector, false); + assertNotNull("There should be a result", result); //$NON-NLS-1$ + assertTrue("The result artifact should be a String", result.getArtifact() instanceof IStackFrame); //$NON-NLS-1$ + assertTrue("The result source element should be a String", result.getSourceElement() instanceof String); //$NON-NLS-1$ + assertEquals("The results should not be equal", value, result.getSourceElement()); //$NON-NLS-1$ + } finally { + SourceLookupFacility.shutdown(); + } + } + + /** + * Tests calling + * {@link SourceLookupFacility#lookup(Object, org.eclipse.debug.core.model.ISourceLocator, boolean)} + * with an {@link IStackFrame} impl and forcing + * + * @throws Exception + */ + public void testLookupStackframeForce() throws Exception { + try { + ISourceLookupResult result = SourceLookupFacility.getDefault().lookup(fReusableFrame, fTestDirector, true); + assertNotNull("There should be a result", result); //$NON-NLS-1$ + assertTrue("The result source element should be a String", result.getArtifact() instanceof IStackFrame); //$NON-NLS-1$ + assertTrue("The result source element should be a String", result.getSourceElement() instanceof String); //$NON-NLS-1$ + String value = (String) result.getSourceElement(); + result = SourceLookupFacility.getDefault().lookup(fReusableFrame, fTestDirector, true); + assertNotNull("There should be a result", result); //$NON-NLS-1$ + assertTrue("The result artifact should be a String", result.getArtifact() instanceof IStackFrame); //$NON-NLS-1$ + assertTrue("The result source element should be a String", result.getSourceElement() instanceof String); //$NON-NLS-1$ + assertNotSame("The results should not be equal", value, result.getSourceElement()); //$NON-NLS-1$ + } finally { + SourceLookupFacility.shutdown(); + } + } + + /** + * Tests calling + * {@link SourceLookupFacility#lookup(Object, org.eclipse.debug.core.model.ISourceLocator, boolean)} + * with an {@link IStackFrame} impl, no forcing, no locator, no launch + * + * @throws Exception + */ + public void testLookupStackframeWithDebugElement1() throws Exception { + try { + ISourceLookupResult result = SourceLookupFacility.getDefault().lookup(new TestStackFrame(null), null, false); + assertNotNull("There should be a result", result); //$NON-NLS-1$ + assertNull("Source element should be null", result.getSourceElement()); //$NON-NLS-1$ + } finally { + SourceLookupFacility.shutdown(); + } + } + + /** + * Tests calling + * {@link SourceLookupFacility#lookup(Object, org.eclipse.debug.core.model.ISourceLocator, boolean)} + * with an {@link IStackFrame} impl, no forcing, no locator + * + * @throws Exception + */ + public void testLookupStackframeWithDebugElement2() throws Exception { + try { + ISourceLookupResult result = SourceLookupFacility.getDefault().lookup(fReusableFrame, null, false); + assertNotNull("There should be a result", result); //$NON-NLS-1$ + assertTrue("The result source element should be a String", result.getArtifact() instanceof IStackFrame); //$NON-NLS-1$ + assertTrue("The result source element should be a String", result.getSourceElement() instanceof String); //$NON-NLS-1$ + String value = (String) result.getSourceElement(); + result = SourceLookupFacility.getDefault().lookup(fReusableFrame, null, false); + assertNotNull("There should be a result", result); //$NON-NLS-1$ + assertTrue("The result artifact should be a String", result.getArtifact() instanceof IStackFrame); //$NON-NLS-1$ + assertTrue("The result source element should be a String", result.getSourceElement() instanceof String); //$NON-NLS-1$ + assertEquals("The results should be equal", value, result.getSourceElement()); //$NON-NLS-1$ + } finally { + SourceLookupFacility.shutdown(); + } + } + + /** + * Tests calling + * {@link SourceLookupFacility#lookup(Object, org.eclipse.debug.core.model.ISourceLocator, boolean)} + * with an {@link IStackFrame} impl, forcing, no locator + * + * @throws Exception + */ + public void testLookupStackframeWithDebugElement3() throws Exception { + try { + ISourceLookupResult result = SourceLookupFacility.getDefault().lookup(fReusableFrame, null, true); + assertNotNull("There should be a result", result); //$NON-NLS-1$ + assertTrue("The result source element should be a String", result.getArtifact() instanceof IStackFrame); //$NON-NLS-1$ + assertTrue("The result source element should be a String", result.getSourceElement() instanceof String); //$NON-NLS-1$ + String value = (String) result.getSourceElement(); + result = SourceLookupFacility.getDefault().lookup(fReusableFrame, null, true); + assertNotNull("There should be a result", result); //$NON-NLS-1$ + assertTrue("The result artifact should be a String", result.getArtifact() instanceof IStackFrame); //$NON-NLS-1$ + assertTrue("The result source element should be a String", result.getSourceElement() instanceof String); //$NON-NLS-1$ + assertNotSame("The results should not be equal", value, result.getSourceElement()); //$NON-NLS-1$ + } finally { + SourceLookupFacility.shutdown(); + } + } + + /** + * Tests calling + * {@link SourceLookupFacility#lookup(Object, org.eclipse.debug.core.model.ISourceLocator, boolean)} + * with an {@link IStackFrame} impl, no forcing, ISourceLocator impl + * + * @throws Exception + */ + public void testLookupStackframeWithDebugElement4() throws Exception { + try { + ISourceLookupResult result = SourceLookupFacility.getDefault().lookup(fReusableFrame, fTestLocator, false); + assertNotNull("There should be a result", result); //$NON-NLS-1$ + assertTrue("The result source element should be a String", result.getArtifact() instanceof IStackFrame); //$NON-NLS-1$ + assertTrue("The result source element should be a String", result.getSourceElement() instanceof String); //$NON-NLS-1$ + String value = (String) result.getSourceElement(); + result = SourceLookupFacility.getDefault().lookup(fReusableFrame, fTestLocator, false); + assertNotNull("There should be a result", result); //$NON-NLS-1$ + assertTrue("The result artifact should be a String", result.getArtifact() instanceof IStackFrame); //$NON-NLS-1$ + assertTrue("The result source element should be a String", result.getSourceElement() instanceof String); //$NON-NLS-1$ + assertEquals("The results should not be equal", value, result.getSourceElement()); //$NON-NLS-1$ + } finally { + SourceLookupFacility.shutdown(); + } + } + + /** + * Tests calling + * {@link SourceLookupFacility#lookup(Object, org.eclipse.debug.core.model.ISourceLocator, boolean)} + * with an {@link IStackFrame} impl, forcing, ISourceLocator impl + * + * @throws Exception + */ + public void testLookupStackframeWithDebugElement5() throws Exception { + try { + ISourceLookupResult result = SourceLookupFacility.getDefault().lookup(fReusableFrame, fTestLocator, true); + assertNotNull("There should be a result", result); //$NON-NLS-1$ + assertTrue("The result source element should be a String", result.getArtifact() instanceof IStackFrame); //$NON-NLS-1$ + assertTrue("The result source element should be a String", result.getSourceElement() instanceof String); //$NON-NLS-1$ + String value = (String) result.getSourceElement(); + result = SourceLookupFacility.getDefault().lookup(fReusableFrame, fTestLocator, true); + assertNotNull("There should be a result", result); //$NON-NLS-1$ + assertTrue("The result artifact should be a String", result.getArtifact() instanceof IStackFrame); //$NON-NLS-1$ + assertTrue("The result source element should be a String", result.getSourceElement() instanceof String); //$NON-NLS-1$ + assertNotSame("The results should not be equal", value, result.getSourceElement()); //$NON-NLS-1$ + } finally { + SourceLookupFacility.shutdown(); + } + } +} diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/sourcelookup/TestLaunch.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/sourcelookup/TestLaunch.java new file mode 100644 index 000000000..2c94c0e56 --- /dev/null +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/sourcelookup/TestLaunch.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2014 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.tests.sourcelookup; + +import org.eclipse.debug.core.Launch; + +public class TestLaunch extends Launch { + + public TestLaunch() { + super(null, "debug", new TestSourceDirector()); //$NON-NLS-1$ + } + +} diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/sourcelookup/TestSourceDirector.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/sourcelookup/TestSourceDirector.java new file mode 100644 index 000000000..6ec38faaa --- /dev/null +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/sourcelookup/TestSourceDirector.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2014 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.tests.sourcelookup; + +import org.eclipse.debug.core.model.IStackFrame; +import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector; + +public class TestSourceDirector extends AbstractSourceLookupDirector { + + + @Override + public Object getSourceElement(Object element) { + if (element instanceof String) { + return element.toString() + System.currentTimeMillis(); + } else if (element instanceof IStackFrame) { + IStackFrame frame = (IStackFrame) element; + return frame.getModelIdentifier() + System.currentTimeMillis(); + } + return super.getSourceElement(element); + } + + @Override + public void initializeParticipants() { + } +} diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/sourcelookup/TestSourceLocator.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/sourcelookup/TestSourceLocator.java new file mode 100644 index 000000000..bff349358 --- /dev/null +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/sourcelookup/TestSourceLocator.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) Jul 30, 2014 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.tests.sourcelookup; + +import org.eclipse.debug.core.model.ISourceLocator; +import org.eclipse.debug.core.model.IStackFrame; + +/** + * Test source locator + */ +public class TestSourceLocator implements ISourceLocator { + + /* (non-Javadoc) + * @see org.eclipse.debug.core.model.ISourceLocator#getSourceElement(org.eclipse.debug.core.model.IStackFrame) + */ + @Override + public Object getSourceElement(IStackFrame stackFrame) { + return stackFrame.getModelIdentifier() + System.currentTimeMillis(); + } + +} diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/sourcelookup/TestStackFrame.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/sourcelookup/TestStackFrame.java new file mode 100644 index 000000000..2e6da1a2c --- /dev/null +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/sourcelookup/TestStackFrame.java @@ -0,0 +1,162 @@ +/******************************************************************************* + * Copyright (c) 2014 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.tests.sourcelookup; + +import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.core.model.IDebugTarget; +import org.eclipse.debug.core.model.IRegisterGroup; +import org.eclipse.debug.core.model.IStackFrame; +import org.eclipse.debug.core.model.IThread; +import org.eclipse.debug.core.model.IVariable; + +public class TestStackFrame implements IStackFrame { + + TestLaunch fLaunch = null; + + public TestStackFrame(TestLaunch launch) { + fLaunch = launch; + } + + @Override + public String getModelIdentifier() { + return "test.debug.model"; //$NON-NLS-1$ + } + + @Override + public IDebugTarget getDebugTarget() { + return null; + } + + @Override + public ILaunch getLaunch() { + return fLaunch; + } + + @Override + public Object getAdapter(Class adapter) { + return null; + } + + @Override + public boolean canStepInto() { + return false; + } + + @Override + public boolean canStepOver() { + return false; + } + + @Override + public boolean canStepReturn() { + return false; + } + + @Override + public boolean isStepping() { + return false; + } + + @Override + public void stepInto() throws DebugException { + } + + @Override + public void stepOver() throws DebugException { + } + + @Override + public void stepReturn() throws DebugException { + } + + @Override + public boolean canResume() { + return false; + } + + @Override + public boolean canSuspend() { + return false; + } + + @Override + public boolean isSuspended() { + return false; + } + + @Override + public void resume() throws DebugException { + } + + @Override + public void suspend() throws DebugException { + } + + @Override + public boolean canTerminate() { + return false; + } + + @Override + public boolean isTerminated() { + return false; + } + + @Override + public void terminate() throws DebugException { + } + + @Override + public IThread getThread() { + return null; + } + + @Override + public IVariable[] getVariables() throws DebugException { + return new IVariable[0]; + } + + @Override + public boolean hasVariables() throws DebugException { + return false; + } + + @Override + public int getLineNumber() throws DebugException { + return 0; + } + + @Override + public int getCharStart() throws DebugException { + return 0; + } + + @Override + public int getCharEnd() throws DebugException { + return 0; + } + + @Override + public String getName() throws DebugException { + return "Test Debug Source Lookup Frame"; //$NON-NLS-1$ + } + + @Override + public IRegisterGroup[] getRegisterGroups() throws DebugException { + return new IRegisterGroup[0]; + } + + @Override + public boolean hasRegisterGroups() throws DebugException { + return false; + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/StackFrameSourceDisplayAdapter.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/StackFrameSourceDisplayAdapter.java index a62505d4b..3d41de771 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/StackFrameSourceDisplayAdapter.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/StackFrameSourceDisplayAdapter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2013 IBM Corporation and others. + * Copyright (c) 2005, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,239 +10,20 @@ *******************************************************************************/ package org.eclipse.debug.internal.ui.elements.adapters; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.debug.core.DebugEvent; -import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.core.IDebugEventSetListener; -import org.eclipse.debug.core.model.IDebugElement; -import org.eclipse.debug.core.model.IDebugTarget; -import org.eclipse.debug.core.model.ISourceLocator; -import org.eclipse.debug.core.model.IStackFrame; -import org.eclipse.debug.core.model.IThread; -import org.eclipse.debug.internal.ui.InstructionPointerManager; -import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupResult; -import org.eclipse.debug.internal.ui.views.launch.DecorationManager; -import org.eclipse.debug.ui.DebugUITools; +import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupFacility; import org.eclipse.debug.ui.sourcelookup.ISourceDisplay; -import org.eclipse.debug.ui.sourcelookup.ISourceLookupResult; import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.progress.UIJob; /** * @since 3.2 */ public class StackFrameSourceDisplayAdapter implements ISourceDisplay { - private IStackFrame fPrevFrame; - private SourceLookupResult fPrevResult; - - /** - * Constructs singleton source display adapter for stack frames. - */ - public StackFrameSourceDisplayAdapter() { - DebugPlugin.getDefault().addDebugEventListener(new IDebugEventSetListener() { - @Override - public void handleDebugEvents(DebugEvent[] events) { - for (int i = 0; i < events.length; i++) { - final DebugEvent event = events[i]; - switch (event.getKind()) { - case DebugEvent.TERMINATE: - clearCachedModel(event.getSource()); - //$FALL-THROUGH$ - case DebugEvent.RESUME: - if (!event.isEvaluation()) { - Job uijob = new UIJob("clear source selection"){ //$NON-NLS-1$ - @Override - public IStatus runInUIThread( - IProgressMonitor monitor) { - clearSourceSelection(event.getSource()); - return Status.OK_STATUS; - } - - }; - uijob.setSystem(true); - uijob.schedule(); - } - break; - case DebugEvent.CHANGE: - if (event.getSource() instanceof IStackFrame) { - if (event.getDetail() == DebugEvent.CONTENT) { - // force source lookup if a stack frame fires a content change event - clearCachedModel(event.getSource()); - } - } - break; - default: - break; - } - } - } - }); - } - - /** - * A job to perform source lookup on the currently selected stack frame. - */ - class SourceLookupJob extends Job { - - private IStackFrame fTarget; - private ISourceLocator fLocator; - private IWorkbenchPage fPage; - - /** - * Constructs a new source lookup job. - */ - public SourceLookupJob(IStackFrame frame, ISourceLocator locator, IWorkbenchPage page) { - super("Debug Source Lookup"); //$NON-NLS-1$ - setPriority(Job.INTERACTIVE); - setSystem(true); - fTarget = frame; - fLocator = locator; - fPage = page; - // Note: Be careful when trying to use scheduling rules with this - // job, in order to avoid blocking nested jobs (bug 339542). - } - - /* (non-Javadoc) - * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) - */ - @Override - protected IStatus run(IProgressMonitor monitor) { - if (!monitor.isCanceled()) { - if (!fTarget.isTerminated()) { - ISourceLookupResult result = DebugUITools.lookupSource(fTarget, fLocator); - synchronized (StackFrameSourceDisplayAdapter.this) { - fPrevResult = (SourceLookupResult)result; - fPrevFrame = fTarget; - } - if (!monitor.isCanceled() && !fTarget.isTerminated()) { - new SourceDisplayJob(result, fPage).schedule(); - } - } - } - return Status.OK_STATUS; - } - - /* (non-Javadoc) - * @see org.eclipse.core.runtime.jobs.Job#belongsTo(java.lang.Object) - */ - @Override - public boolean belongsTo(Object family) { - // source lookup jobs are a family per workbench page - if (family instanceof SourceLookupJob) { - SourceLookupJob slj = (SourceLookupJob) family; - return slj.fPage.equals(fPage); - } - return false; - } - - } - - class SourceDisplayJob extends UIJob { - - private ISourceLookupResult fResult; - private IWorkbenchPage fPage; - - public SourceDisplayJob(ISourceLookupResult result, IWorkbenchPage page) { - super("Debug Source Display"); //$NON-NLS-1$ - setSystem(true); - setPriority(Job.INTERACTIVE); - fResult = result; - fPage = page; - } - - - /* (non-Javadoc) - * @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor) - */ - @Override - public IStatus runInUIThread(IProgressMonitor monitor) { - if (!monitor.isCanceled() && fResult != null) { - DebugUITools.displaySource(fResult, fPage); - // termination may have occurred while displaying source - if (monitor.isCanceled()) { - Object artifact = fResult.getArtifact(); - if (artifact instanceof IStackFrame) { - clearSourceSelection(((IStackFrame)artifact).getThread()); - } - } - } - - return Status.OK_STATUS; - } - - /* (non-Javadoc) - * @see org.eclipse.core.runtime.jobs.Job#belongsTo(java.lang.Object) - */ - @Override - public boolean belongsTo(Object family) { - // source display jobs are a family per workbench page - if (family instanceof SourceDisplayJob) { - SourceDisplayJob sdj = (SourceDisplayJob) family; - return sdj.fPage.equals(fPage); - } - return false; - } - - } - /* (non-Javadoc) * @see org.eclipse.debug.ui.contexts.ISourceDisplayAdapter#displaySource(java.lang.Object, org.eclipse.ui.IWorkbenchPage, boolean) */ @Override public synchronized void displaySource(Object context, IWorkbenchPage page, boolean force) { - IStackFrame frame = (IStackFrame)context; - if (!force && frame.equals(fPrevFrame)) { - fPrevResult.updateArtifact(context); - SourceDisplayJob sdj = new SourceDisplayJob(fPrevResult, page); - // cancel any existing source display jobs for this page - Job.getJobManager().cancel(sdj); - sdj.schedule(); - } else { - SourceLookupJob slj = new SourceLookupJob(frame, frame.getLaunch().getSourceLocator(), page); - // cancel any existing source lookup jobs for this page - Job.getJobManager().cancel(slj); - slj.schedule(); - } - } - - /** - * Clears any source decorations associated with the given thread or - * debug target. - * - * @param source thread or debug target - */ - private void clearSourceSelection(Object source) { - if (source instanceof IThread) { - IThread thread = (IThread)source; - DecorationManager.removeDecorations(thread); - InstructionPointerManager.getDefault().removeAnnotations(thread); - } else if (source instanceof IDebugTarget) { - IDebugTarget target = (IDebugTarget)source; - DecorationManager.removeDecorations(target); - InstructionPointerManager.getDefault().removeAnnotations(target); - } - } - - /** - * Clear any cached results associated with the given object. - * - * @param source - */ - private synchronized void clearCachedModel(Object source) { - if (fPrevFrame != null) { - IDebugTarget target = null; - if (source instanceof IDebugElement) { - target = ((IDebugElement)source).getDebugTarget(); - } - if (fPrevFrame.getDebugTarget().equals(target)) { - fPrevFrame = null; - fPrevResult = null; - } - } + SourceLookupFacility.getDefault().displaySource(context, page, force); } - } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceLookupFacility.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceLookupFacility.java index cfdae31d5..a9c655aa4 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceLookupFacility.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceLookupFacility.java @@ -49,7 +49,6 @@ import org.eclipse.debug.ui.IDebugUIConstants; import org.eclipse.debug.ui.IInstructionPointerPresentation; import org.eclipse.debug.ui.ISourcePresentation; import org.eclipse.debug.ui.sourcelookup.CommonSourceNotFoundEditorInput; -import org.eclipse.debug.ui.sourcelookup.ISourceDisplay; import org.eclipse.debug.ui.sourcelookup.ISourceLookupResult; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; @@ -77,7 +76,7 @@ import org.eclipse.ui.texteditor.ITextEditor; * * @since 3.1 */ -public class SourceLookupFacility implements IPageListener, IPartListener2, IPropertyChangeListener, ISourceDisplay { +public class SourceLookupFacility implements IPageListener, IPartListener2, IPropertyChangeListener, IDebugEventSetListener { /** * Provides an LRU cache with a given max size @@ -106,7 +105,6 @@ public class SourceLookupFacility implements IPageListener, IPartListener2, IPro */ @Override public SourceLookupResult put(Object key, SourceLookupResult value) { - shuffle(key); return super.put(key, value); } @@ -168,8 +166,6 @@ public class SourceLookupFacility implements IPageListener, IPartListener2, IPro * Whether to re-use editors when displaying source. */ private boolean fReuseEditor = DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IDebugUIConstants.PREF_REUSE_EDITOR); - private IStackFrame fPrevFrame; - private SourceLookupResult fPrevResult; /** * Constructs singleton source display adapter for stack frames. @@ -193,7 +189,6 @@ public class SourceLookupFacility implements IPageListener, IPartListener2, IPro if (fgDefault != null) { fgDefault.dispose(); } - fLookupResults.clear(); } /** @@ -202,44 +197,42 @@ public class SourceLookupFacility implements IPageListener, IPartListener2, IPro private SourceLookupFacility() { fEditorsByPage = new HashMap<IWorkbenchPage, IEditorPart>(); DebugUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(this); - DebugPlugin.getDefault().addDebugEventListener(new IDebugEventSetListener() { - @Override - public void handleDebugEvents(DebugEvent[] events) { - for (int i = 0; i < events.length; i++) { - final DebugEvent event = events[i]; - switch (event.getKind()) { - case DebugEvent.TERMINATE: - clearCachedModel(event.getSource()); - //$FALL-THROUGH$ - case DebugEvent.RESUME: - if (!event.isEvaluation()) { - Job uijob = new UIJob("clear source selection") { //$NON-NLS-1$ - @Override - public IStatus runInUIThread(IProgressMonitor monitor) { - clearSourceSelection(event.getSource()); - return Status.OK_STATUS; - } - - }; - uijob.setSystem(true); - uijob.schedule(); - } - break; - case DebugEvent.CHANGE: - if (event.getSource() instanceof IStackFrame) { - if (event.getDetail() == DebugEvent.CONTENT) { - // force source lookup if a stack frame - // fires a content change event - clearCachedModel(event.getSource()); - } + DebugPlugin.getDefault().addDebugEventListener(this); + } + + @Override + public void handleDebugEvents(DebugEvent[] events) { + IStackFrame frame = null; + for (int i = 0; i < events.length; i++) { + final DebugEvent event = events[i]; + switch (event.getKind()) { + case DebugEvent.TERMINATE: + case DebugEvent.RESUME: + if (!event.isEvaluation()) { + Job uijob = new UIJob("clear source selection") { //$NON-NLS-1$ + @Override + public IStatus runInUIThread(IProgressMonitor monitor) { + clearSourceSelection(event.getSource()); + return Status.OK_STATUS; } - break; - default: - break; + + }; + uijob.setSystem(true); + uijob.schedule(); } - } + break; + case DebugEvent.CHANGE: + if (event.getSource() instanceof IStackFrame) { + if (event.getDetail() == DebugEvent.CONTENT) { + frame = (IStackFrame) event.getSource(); + fLookupResults.remove(new ArtifactWithLocator(frame, frame.getLaunch().getSourceLocator())); + } + } + break; + default: + break; } - }); + } } private class ArtifactWithLocator { @@ -313,14 +306,18 @@ public class SourceLookupFacility implements IPageListener, IPartListener2, IPro * <code>null</code> a source locator is determined from the * artifact, if possible. If the artifact is a debug element, the * source locator from its associated launch is used. + * @param force If we should ignore the cached value and re-look up * @return a source lookup result */ - public SourceLookupResult lookup(Object artifact, ISourceLocator locator) { + public SourceLookupResult lookup(Object artifact, ISourceLocator locator, boolean force) { SourceLookupResult result = null; synchronized (fLookupResults) { - result = fLookupResults.get(new ArtifactWithLocator(artifact, locator)); - if (result != null) { - return result; + ArtifactWithLocator key = new ArtifactWithLocator(artifact, locator); + if (!force) { + result = fLookupResults.get(key); + if (result != null) { + return result; + } } result = new SourceLookupResult(artifact, null, null, null); IDebugElement debugElement = null; @@ -379,7 +376,7 @@ public class SourceLookupFacility implements IPageListener, IPartListener2, IPro result.setEditorInput(editorInput); result.setEditorId(editorId); result.setSourceElement(sourceElement); - fLookupResults.put(new ArtifactWithLocator(artifact, localLocator), result); + fLookupResults.put(key, result); } } return result; @@ -698,8 +695,10 @@ public class SourceLookupFacility implements IPageListener, IPartListener2, IPro */ protected void dispose() { DebugUIPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(this); + DebugPlugin.getDefault().removeDebugEventListener(this); fEditorsByPage.clear(); fPresentation.dispose(); + fLookupResults.clear(); } /** @@ -710,17 +709,19 @@ public class SourceLookupFacility implements IPageListener, IPartListener2, IPro private IStackFrame fTarget; private ISourceLocator fLocator; private IWorkbenchPage fPage; + private boolean fForce = false; /** * Constructs a new source lookup job. */ - public SourceLookupJob(IStackFrame frame, ISourceLocator locator, IWorkbenchPage page) { + public SourceLookupJob(IStackFrame frame, ISourceLocator locator, IWorkbenchPage page, boolean force) { super("Debug Source Lookup"); //$NON-NLS-1$ setPriority(Job.INTERACTIVE); setSystem(true); fTarget = frame; fLocator = locator; fPage = page; + fForce = force; // Note: Be careful when trying to use scheduling rules with this // job, in order to avoid blocking nested jobs (bug 339542). } @@ -734,11 +735,7 @@ public class SourceLookupFacility implements IPageListener, IPartListener2, IPro protected IStatus run(IProgressMonitor monitor) { if (!monitor.isCanceled()) { if (!fTarget.isTerminated()) { - ISourceLookupResult result = lookup(fTarget, fLocator); - synchronized (SourceLookupFacility.this) { - fPrevResult = (SourceLookupResult) result; - fPrevFrame = fTarget; - } + ISourceLookupResult result = lookup(fTarget, fLocator, fForce); if (!monitor.isCanceled() && !fTarget.isTerminated() && fPage != null) { new SourceDisplayJob(result, fPage).schedule(); } @@ -820,21 +817,12 @@ public class SourceLookupFacility implements IPageListener, IPartListener2, IPro * org.eclipse.debug.ui.contexts.ISourceDisplayAdapter#displaySource(java * .lang.Object, org.eclipse.ui.IWorkbenchPage, boolean) */ - @Override public synchronized void displaySource(Object context, IWorkbenchPage page, boolean force) { IStackFrame frame = (IStackFrame) context; - if (!force && frame.equals(fPrevFrame)) { - fPrevResult.updateArtifact(context); - SourceDisplayJob sdj = new SourceDisplayJob(fPrevResult, page); - // cancel any existing source display jobs for this page - Job.getJobManager().cancel(sdj); - sdj.schedule(); - } else { - SourceLookupJob slj = new SourceLookupJob(frame, frame.getLaunch().getSourceLocator(), page); - // cancel any existing source lookup jobs for this page - Job.getJobManager().cancel(slj); - slj.schedule(); - } + SourceLookupJob slj = new SourceLookupJob(frame, frame.getLaunch().getSourceLocator(), page, force); + // cancel any existing source lookup jobs for this page + Job.getJobManager().cancel(slj); + slj.schedule(); } /** @@ -854,22 +842,4 @@ public class SourceLookupFacility implements IPageListener, IPartListener2, IPro InstructionPointerManager.getDefault().removeAnnotations(target); } } - - /** - * Clear any cached results associated with the given object. - * - * @param source - */ - private synchronized void clearCachedModel(Object source) { - if (fPrevFrame != null) { - IDebugTarget target = null; - if (source instanceof IDebugElement) { - target = ((IDebugElement) source).getDebugTarget(); - } - if (fPrevFrame.getDebugTarget().equals(target)) { - fPrevFrame = null; - fPrevResult = null; - } - } - } } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/DebugElementAdapterFactory.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/DebugElementAdapterFactory.java index 59a7e9be1..6475b0969 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/DebugElementAdapterFactory.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/DebugElementAdapterFactory.java @@ -37,6 +37,7 @@ import org.eclipse.debug.internal.ui.elements.adapters.MemoryBlockContentAdapter import org.eclipse.debug.internal.ui.elements.adapters.MemoryBlockLabelAdapter; import org.eclipse.debug.internal.ui.elements.adapters.MemoryRetrievalContentAdapter; import org.eclipse.debug.internal.ui.elements.adapters.MemorySegmentLabelAdapter; +import org.eclipse.debug.internal.ui.elements.adapters.StackFrameSourceDisplayAdapter; import org.eclipse.debug.internal.ui.elements.adapters.StackFrameViewerInputProvider; import org.eclipse.debug.internal.ui.elements.adapters.VariableColumnFactoryAdapter; import org.eclipse.debug.internal.ui.model.elements.BreakpointContainerLabelProvider; @@ -71,7 +72,6 @@ import org.eclipse.debug.internal.ui.model.elements.VariableEditor; import org.eclipse.debug.internal.ui.model.elements.VariableLabelProvider; import org.eclipse.debug.internal.ui.model.elements.VariableMementoProvider; import org.eclipse.debug.internal.ui.model.elements.WatchExpressionEditor; -import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupFacility; import org.eclipse.debug.internal.ui.viewers.model.provisional.IColumnPresentationFactory; import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementContentProvider; import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementEditor; @@ -93,7 +93,7 @@ import org.eclipse.debug.ui.sourcelookup.ISourceDisplay; public class DebugElementAdapterFactory implements IAdapterFactory { private static IModelProxyFactory fgModelProxyFactoryAdapter = new DefaultModelProxyFactory(); - private static ISourceDisplay fgStackFrameSourceDisplayAdapter = SourceLookupFacility.getDefault(); + private static ISourceDisplay fgStackFrameSourceDisplayAdapter = new StackFrameSourceDisplayAdapter(); private static IModelSelectionPolicyFactory fgModelSelectionPolicyFactoryAdapter = new DefaultModelSelectionPolicyFactory(); private static IAsynchronousLabelAdapter fgDebugLabelAdapter = new AsynchronousDebugLabelAdapter(); diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/DebugUITools.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/DebugUITools.java index ab92b7437..cb5b1b94e 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/DebugUITools.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/DebugUITools.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -989,7 +989,7 @@ public class DebugUITools { * @since 3.1 */ public static ISourceLookupResult lookupSource(Object artifact, ISourceLocator locator) { - return SourceLookupFacility.getDefault().lookup(artifact, locator); + return SourceLookupFacility.getDefault().lookup(artifact, locator, false); } /** |