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