Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4f8fa16a295e2ef47e52ee8957dc75caca05565d (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*******************************************************************************
 * Copyright (c) 2005, 2015 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.core.model;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.PlatformObject;
import org.eclipse.core.runtime.Status;

import org.eclipse.debug.core.DebugEvent;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;

/**
 * Implementation of common function for debug elements.
 * <p>
 * Clients may subclass this class.
 * </p>
 * @since 3.1
 */
public abstract class DebugElement extends PlatformObject implements IDebugElement {

    private IDebugTarget fTarget;

    /**
     * Constructs a debug element referring to an artifact in the given
     * debug target.
     *
     * @param target debug target containing this element
     */
    public DebugElement(IDebugTarget target) {
        fTarget = target;
    }

    /* (non-Javadoc)
     *
     * Debug target implementation should override this method.
     *
     * @see org.eclipse.debug.core.model.IDebugElement#getDebugTarget()
     */
    @Override
	public IDebugTarget getDebugTarget() {
        return fTarget;
    }

    /* (non-Javadoc)
     * @see org.eclipse.debug.core.model.IDebugElement#getLaunch()
     */
    @Override
	public ILaunch getLaunch() {
        return getDebugTarget().getLaunch();
    }

    /* (non-Javadoc)
     * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
     */
	@SuppressWarnings("unchecked")
	@Override
	public <T> T getAdapter(Class<T> adapter) {
		if (adapter == IDebugElement.class) {
			return (T) this;
		}

		// a debug target may not implement IStepFilters
		if (adapter == IStepFilters.class) {
			if (getDebugTarget() instanceof IStepFilters) {
				return (T) getDebugTarget();
			}
		}
		if (adapter == IDebugTarget.class) {
			return (T) getDebugTarget();
		}
		if (adapter == ILaunch.class) {
			return (T) getLaunch();
		}
		if (adapter == IProcess.class) {
			return (T) getDebugTarget().getProcess();
		}
		//CONTEXTLAUNCHING
		if(adapter == ILaunchConfiguration.class) {
			return (T) getLaunch().getLaunchConfiguration();
		}
		return super.getAdapter(adapter);
    }

	/**
	 * Fires a debug event.
	 *
	 * @param event debug event to fire
	 */
	public void fireEvent(DebugEvent event) {
		DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] {event});
	}

	/**
	 * Fires a change event for this debug element
	 * with the specified detail code.
	 *
	 * @param detail detail code for the change event,
	 *  such as <code>DebugEvent.STATE</code> or <code>DebugEvent.CONTENT</code>
	 */
	public void fireChangeEvent(int detail) {
		fireEvent(new DebugEvent(this, DebugEvent.CHANGE, detail));
	}

	/**
	 * Fires a creation event for this debug element.
	 */
    public void fireCreationEvent() {
		fireEvent(new DebugEvent(this, DebugEvent.CREATE));
	}

	/**
	 * Fires a resume for this debug element with
	 * the specified detail code.
	 *
	 * @param detail detail code for the resume event, such
	 *  as <code>DebugEvent.STEP_OVER</code>
	 */
    public void fireResumeEvent(int detail) {
		fireEvent(new DebugEvent(this, DebugEvent.RESUME, detail));
	}

	/**
	 * Fires a suspend event for this debug element with
	 * the specified detail code.
	 *
	 * @param detail detail code for the suspend event, such
	 *  as <code>DebugEvent.BREAKPOINT</code>
	 */
    public void fireSuspendEvent(int detail) {
		fireEvent(new DebugEvent(this, DebugEvent.SUSPEND, detail));
	}

	/**
	 * Fires a terminate event for this debug element.
	 */
    public void fireTerminateEvent() {
		fireEvent(new DebugEvent(this, DebugEvent.TERMINATE));
	}

	/**
	 * Throws a debug exception with a status code of <code>TARGET_REQUEST_FAILED</code>.
	 *
	 * @param message exception message
	 * @param e underlying exception or <code>null</code>
	 * @throws DebugException if a problem is encountered
	 */
	protected void requestFailed(String message, Throwable e) throws DebugException {
		throw new DebugException(new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(),
				DebugException.TARGET_REQUEST_FAILED, message, e));
	}

	/**
	 * Throws a debug exception with a status code of <code>NOT_SUPPORTED</code>.
	 *
	 * @param message exception message
	 * @param e underlying exception or <code>null</code>
	 * @throws DebugException if a problem is encountered
	 */
	protected void notSupported(String message, Throwable e) throws DebugException {
		throw new DebugException(new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(),
				DebugException.NOT_SUPPORTED, message, e));
	}
}

Back to the top