Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 2a1cc32893fd23056645c2837cc422fef233ff44 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*******************************************************************************
 * Copyright (c) 2020 Paul Pazderski and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     Paul Pazderski - initial API and implementation
 *******************************************************************************/
package org.eclipse.debug.tests.breakpoint;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.debug.core.model.Breakpoint;
import org.eclipse.debug.core.model.IBreakpoint;

/**
 * Test only implementation of IBreakpoint.
 */
public class TestBreakpoint extends Breakpoint {

	public static final String MODEL = "org.eclipse.debug.tests"; //$NON-NLS-1$
	public static final String TEXT_ATTRIBUTE = "org.eclipse.debug.tests.breakpoint.TestBreakpoint.text"; //$NON-NLS-1$

	public TestBreakpoint() {
		super();
	}

	TestBreakpoint(String text) {
		this(text, IBreakpoint.BREAKPOINT_MARKER);
	}

	TestBreakpoint(String text, final String markerType) {
		final IResource resource = ResourcesPlugin.getWorkspace().getRoot();
		IWorkspaceRunnable wr = new IWorkspaceRunnable() {
			@Override
			public void run(IProgressMonitor monitor) throws CoreException {
				// create the marker
				setMarker(resource.createMarker(markerType));
				ensureMarker().setAttribute(ID, getModelIdentifier());
				ensureMarker().setAttribute(TEXT_ATTRIBUTE, text);
			}
		};
		try {
			ResourcesPlugin.getWorkspace().run(wr, null);
		} catch (CoreException e) {
			fail("Unexpected exception: " + e); //$NON-NLS-1$
		}

	}

	public String getText() {
		return getMarker().getAttribute(TEXT_ATTRIBUTE, null);
	}

	@Override
	public String getModelIdentifier() {
		return MODEL;
	}

	@Override
	public void setMarker(IMarker marker) throws CoreException {
		assertTrue(getMarker() == null && marker != null);
		super.setMarker(marker);
	}

}

Back to the top