1 11 12 package org.eclipse.jdt.launching.sourcelookup.containers; 13 14 import java.util.HashMap ; 15 import java.util.Iterator ; 16 import java.util.Map ; 17 18 import org.eclipse.core.resources.IFile; 19 import org.eclipse.core.resources.IProject; 20 import org.eclipse.core.runtime.CoreException; 21 import org.eclipse.core.runtime.IPath; 22 import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupParticipant; 23 import org.eclipse.debug.core.sourcelookup.ISourceContainer; 24 import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector; 25 import org.eclipse.debug.core.sourcelookup.containers.ArchiveSourceContainer; 26 import org.eclipse.jdt.core.IJavaProject; 27 import org.eclipse.jdt.core.IPackageFragmentRoot; 28 import org.eclipse.jdt.core.JavaCore; 29 import org.eclipse.jdt.core.JavaModelException; 30 import org.eclipse.jdt.internal.debug.core.JavaDebugUtils; 31 32 40 public class JavaSourceLookupParticipant extends AbstractSourceLookupParticipant { 41 42 47 private Map fDelegateContainers; 48 49 59 public String getSourceName(Object object) throws CoreException { 60 return JavaDebugUtils.getSourceName(object); 61 } 62 63 66 public void dispose() { 67 Iterator iterator = fDelegateContainers.values().iterator(); 68 while (iterator.hasNext()) { 69 ISourceContainer container = (ISourceContainer) iterator.next(); 70 container.dispose(); 71 } 72 fDelegateContainers = null; 73 super.dispose(); 74 75 } 76 77 80 protected ISourceContainer getDelegateContainer(ISourceContainer container) { 81 ISourceContainer delegate = (ISourceContainer) fDelegateContainers.get(container); 82 if (delegate == null) { 83 return container; 84 } 85 return delegate; 86 } 87 90 public void init(ISourceLookupDirector director) { 91 super.init(director); 92 fDelegateContainers = new HashMap (); 93 } 94 97 public void sourceContainersChanged(ISourceLookupDirector director) { 98 fDelegateContainers.clear(); 100 ISourceContainer[] containers = director.getSourceContainers(); 101 for (int i = 0; i < containers.length; i++) { 102 ISourceContainer container = containers[i]; 103 if (container.getType().getId().equals(ArchiveSourceContainer.TYPE_ID)) { 104 IFile file = ((ArchiveSourceContainer)container).getFile(); 105 IProject project = file.getProject(); 106 IJavaProject javaProject = JavaCore.create(project); 107 if (javaProject.exists()) { 108 try { 109 IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots(); 110 for (int j = 0; j < roots.length; j++) { 111 IPackageFragmentRoot root = roots[j]; 112 if (file.equals(root.getUnderlyingResource())) { 113 fDelegateContainers.put(container, new PackageFragmentRootSourceContainer(root)); 115 } else { 116 IPath path = root.getSourceAttachmentPath(); 117 if (path != null) { 118 if (file.getFullPath().equals(path)) { 119 fDelegateContainers.put(container, new PackageFragmentRootSourceContainer(root)); 121 } 122 } 123 } 124 } 125 } catch (JavaModelException e) { 126 } 127 } 128 } 129 } 130 } 131 } 132 | Popular Tags |