01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.launching.sourcelookup.containers;
11:
12: import org.eclipse.core.runtime.CoreException;
13: import org.eclipse.core.runtime.IPath;
14: import org.eclipse.debug.core.sourcelookup.ISourceContainer;
15: import org.eclipse.debug.core.sourcelookup.ISourceContainerType;
16: import org.eclipse.debug.core.sourcelookup.containers.CompositeSourceContainer;
17: import org.eclipse.jdt.core.JavaCore;
18: import org.eclipse.jdt.internal.launching.LaunchingPlugin;
19: import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
20: import org.eclipse.jdt.launching.JavaRuntime;
21:
22: /**
23: * A classpath variable source container contains a source container
24: * that is the resolved value of the associated variable.
25: * <p>
26: * This class may be instantiated; this class is not intended to be
27: * subclassed.
28: * </p>
29: * @since 3.0
30: */
31: public class ClasspathVariableSourceContainer extends
32: CompositeSourceContainer {
33:
34: private IPath fVariable;
35: /**
36: * Unique identifier for Java project source container type
37: * (value <code>org.eclipse.jdt.launching.sourceContainer.classpathVariable</code>).
38: */
39: public static final String TYPE_ID = LaunchingPlugin
40: .getUniqueIdentifier()
41: + ".sourceContainer.classpathVariable"; //$NON-NLS-1$
42:
43: /**
44: * Constructs a new source container on the given variable and suffix.
45: *
46: * @param variablePath path representing a Java classpath variable.
47: * The first segment is the variable name, and the following segments
48: * (if any) are appended to the variable.
49: */
50: public ClasspathVariableSourceContainer(IPath variablePath) {
51: fVariable = variablePath;
52: }
53:
54: /* (non-Javadoc)
55: * @see org.eclipse.debug.internal.core.sourcelookup.containers.CompositeSourceContainer#createSourceContainers()
56: */
57: protected ISourceContainer[] createSourceContainers()
58: throws CoreException {
59: IPath path = JavaCore
60: .getClasspathVariable(fVariable.segment(0));
61: if (path == null) {
62: return new ISourceContainer[0];
63: }
64: if (fVariable.segmentCount() > 1) {
65: path = path.append(fVariable.removeFirstSegments(1));
66: }
67: IRuntimeClasspathEntry entry = JavaRuntime
68: .newArchiveRuntimeClasspathEntry(path);
69: return JavaRuntime
70: .getSourceContainers(new IRuntimeClasspathEntry[] { entry });
71: }
72:
73: /* (non-Javadoc)
74: * @see org.eclipse.debug.internal.core.sourcelookup.ISourceContainer#getName()
75: */
76: public String getName() {
77: return fVariable.toOSString();
78: }
79:
80: /**
81: * Returns the variable this container references as a path. The
82: * first segment is the variable name, and the following segments
83: * are appended to the variable's value.
84: *
85: * @return path representing the variable and suffix
86: */
87: public IPath getPath() {
88: return fVariable;
89: }
90:
91: /* (non-Javadoc)
92: * @see org.eclipse.debug.internal.core.sourcelookup.ISourceContainer#getType()
93: */
94: public ISourceContainerType getType() {
95: return getSourceContainerType(TYPE_ID);
96: }
97: }
|