1 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.ILaunchConfiguration; 16 import org.eclipse.debug.core.sourcelookup.ISourceContainer; 17 import org.eclipse.debug.core.sourcelookup.ISourceContainerType; 18 import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector; 19 import org.eclipse.debug.core.sourcelookup.containers.CompositeSourceContainer; 20 import org.eclipse.jdt.core.IClasspathContainer; 21 import org.eclipse.jdt.core.IJavaProject; 22 import org.eclipse.jdt.core.JavaCore; 23 import org.eclipse.jdt.internal.launching.LaunchingPlugin; 24 import org.eclipse.jdt.launching.IRuntimeClasspathEntry; 25 import org.eclipse.jdt.launching.JavaRuntime; 26 27 36 37 public class ClasspathContainerSourceContainer extends CompositeSourceContainer { 38 39 42 private IPath fContainerPath; 43 47 public static final String TYPE_ID = LaunchingPlugin.getUniqueIdentifier() + ".sourceContainer.classpathContainer"; 49 54 public ClasspathContainerSourceContainer(IPath containerPath) { 55 fContainerPath = containerPath; 56 } 57 58 61 public String getName() { 62 IClasspathContainer container = null; 63 try { 64 container = getClasspathContainer(); 65 } catch (CoreException e) { 66 } 67 if (container == null) { 68 return getPath().lastSegment(); 69 } 70 return container.getDescription(); 71 } 72 75 public ISourceContainerType getType() { 76 return getSourceContainerType(TYPE_ID); 77 } 78 79 82 protected ISourceContainer[] createSourceContainers() throws CoreException { 83 IRuntimeClasspathEntry entry = JavaRuntime.newRuntimeContainerClasspathEntry(getPath(), IRuntimeClasspathEntry.USER_CLASSES); 84 IRuntimeClasspathEntry[] entries = JavaRuntime.resolveSourceLookupPath(new IRuntimeClasspathEntry[]{entry}, getDirector().getLaunchConfiguration()); 85 return JavaRuntime.getSourceContainers(entries); 86 } 87 88 93 public IPath getPath() { 94 return fContainerPath; 95 } 96 97 100 public boolean equals(Object obj) { 101 if (obj instanceof ClasspathContainerSourceContainer) { 102 return getPath().equals(((ClasspathContainerSourceContainer)obj).getPath()); 103 } 104 return false; 105 } 106 109 public int hashCode() { 110 return getPath().hashCode(); 111 } 112 113 119 public IClasspathContainer getClasspathContainer() throws CoreException { 120 ISourceLookupDirector director = getDirector(); 121 if (director != null) { 122 ILaunchConfiguration configuration = director.getLaunchConfiguration(); 123 if (configuration != null) { 124 IJavaProject project = JavaRuntime.getJavaProject(configuration); 125 if (project != null) { 126 return JavaCore.getClasspathContainer(getPath(), project); 127 } 128 } 129 } 130 return null; 131 } 132 133 } 134 | Popular Tags |