Skip to main content
summaryrefslogtreecommitdiffstats
blob: 6b87cf1b23e58b4d9cb5cd0b654ae92892b54bbb (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
/*******************************************************************************
 * Copyright (c) 2000, 2007 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.sourcelookup.containers;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.PlatformObject;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector;
import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupParticipant;
import org.eclipse.debug.core.sourcelookup.ISourceContainer;
import org.eclipse.debug.core.sourcelookup.ISourceContainerType;
import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector;
import org.eclipse.debug.core.sourcelookup.ISourceLookupParticipant;

/**
 * Common function for source containers.
 * <p>
 * Clients implementing source containers should subclass this class.
 * </p>
 * @since 3.0
 */
public abstract class AbstractSourceContainer extends PlatformObject implements ISourceContainer {
	
	public static final Object[] EMPTY = new Object[0];
	
	private ISourceLookupDirector fDirector;
	
	/**
	 * Throws an error exception with the given message and underlying exception.
	 * 
	 * @param message error message
	 * @param exception underlying exception, or <code>null</code>
	 * @throws CoreException
	 */
	protected void abort(String message, Throwable exception) throws CoreException {
		IStatus status = new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(), DebugPlugin.ERROR, message, exception);
		throw new CoreException(status);
	}
	
	/**
	 * Throws a warning exception with the given message and underlying exception.
	 * 
	 * @param message error message
	 * @param exception underlying exception, or <code>null</code>
	 * @throws CoreException
	 * @since 3.3
	 */	
	protected void warn(String message, Throwable exception) throws CoreException {
		IStatus status = new Status(IStatus.WARNING, DebugPlugin.getUniqueIdentifier(), DebugPlugin.ERROR, message, exception);
		throw new CoreException(status);
	}
	
	/* (non-Javadoc)
	 * 
	 * By default, do nothing. Subclasses should override as required.
	 * 
	 * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#dispose()
	 */
	public void dispose() {
		fDirector = null;
	}	
	
	/* (non-Javadoc)
	 * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#getSourceContainers()
	 */
	public ISourceContainer[] getSourceContainers() throws CoreException {
		return new ISourceContainer[0];
	}

	/* (non-Javadoc)
	 * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#isComposite()
	 */
	public boolean isComposite() {
		return false;
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#init(org.eclipse.debug.core.sourcelookup.ISourceLookupDirector)
	 */
	public void init(ISourceLookupDirector director) {
		fDirector = director;
	}
	
	/**
	 * Returns the source lookup director this source container registered
	 * in, or <code>null</code> if none.
	 * 
	 * @return the source lookup director this source container registered
	 * in, or <code>null</code> if none
	 */
	protected ISourceLookupDirector getDirector() {
		return fDirector;
	}
	
	/**
	 * Returns whether this container's source should search for duplicate source
	 * elements. Since 3.5, the current participant is consulted to determine if
	 * duplicates should be found. Fall back to querying the source lookup director
	 * if the participant is not an {@link AbstractSourceLookupParticipant}.
	 * 
	 * @return whether to search for duplicate source elements
	 */
	protected boolean isFindDuplicates() {
		ISourceLookupDirector director = getDirector();
		if (director != null) {
			if (director instanceof AbstractSourceLookupDirector) {
				AbstractSourceLookupDirector asld = (AbstractSourceLookupDirector) director;
				ISourceLookupParticipant participant = asld.getCurrentParticipant();
				if (participant instanceof AbstractSourceLookupParticipant	) {
					AbstractSourceLookupParticipant aslp = (AbstractSourceLookupParticipant) participant;
					return aslp.isFindDuplicates();
				}
			}
			return director.isFindDuplicates();
		}
		return false;
	}
	
	/**
	 * Returns the source container type identified by the given id,
	 * or <code>null</code> if none.
	 * 
	 * @param id source container type identifier
	 * @return source container type or <code>null</code>
	 */
	protected ISourceContainerType getSourceContainerType(String id) {
		return DebugPlugin.getDefault().getLaunchManager().getSourceContainerType(id);
	}
}

Back to the top