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.sourcelookup.ISourceContainerType; 16 import org.eclipse.debug.core.sourcelookup.containers.AbstractSourceContainer; 17 import org.eclipse.jdt.core.IClassFile; 18 import org.eclipse.jdt.core.ICompilationUnit; 19 import org.eclipse.jdt.core.IPackageFragment; 20 import org.eclipse.jdt.core.IPackageFragmentRoot; 21 import org.eclipse.jdt.core.JavaCore; 22 import org.eclipse.jdt.internal.launching.LaunchingPlugin; 23 24 35 public class PackageFragmentRootSourceContainer extends AbstractSourceContainer { 36 37 private IPackageFragmentRoot fRoot; 38 42 public static final String TYPE_ID = LaunchingPlugin.getUniqueIdentifier() + ".sourceContainer.packageFragmentRoot"; 44 50 public PackageFragmentRootSourceContainer(IPackageFragmentRoot root) { 51 fRoot = root; 52 } 53 54 57 public Object [] findSourceElements(String name) throws CoreException { 58 int index = name.lastIndexOf('.'); 60 String typeName = name; 61 if (index >= 0) { 62 typeName = typeName.substring(0, index); 64 } 65 typeName = typeName.replace('/', '.'); 66 typeName = typeName.replace('\\', '.'); 67 index = typeName.lastIndexOf('.'); 68 String packageName = ""; if (index >= 0) { 70 packageName = typeName.substring(0, index); 71 typeName = typeName.substring(index + 1); 72 } 73 IPackageFragment fragment = fRoot.getPackageFragment(packageName); 74 if (fragment.exists()) { 75 switch (fragment.getKind()) { 76 case IPackageFragmentRoot.K_BINARY: 77 IClassFile file = fragment.getClassFile(typeName + ".class"); if (file.exists()) { 79 return new Object []{file}; 80 } 81 break; 82 case IPackageFragmentRoot.K_SOURCE: 83 String [] extensions = JavaCore.getJavaLikeExtensions(); 84 for (int i = 0; i < extensions.length; i++) { 85 String ext = extensions[i]; 86 ICompilationUnit unit = fragment.getCompilationUnit(typeName + '.' + ext); 87 if (unit.exists()) { 88 return new Object []{unit}; 89 } 90 } 91 break; 92 } 93 94 } 95 return EMPTY; 96 } 97 100 public String getName() { 101 return fRoot.getElementName(); 102 } 103 106 public ISourceContainerType getType() { 107 return getSourceContainerType(TYPE_ID); 108 } 109 110 113 public boolean equals(Object obj) { 114 return obj instanceof PackageFragmentRootSourceContainer && 115 ((PackageFragmentRootSourceContainer)obj).getPackageFragmentRoot().equals(getPackageFragmentRoot()); 116 } 117 118 123 public IPackageFragmentRoot getPackageFragmentRoot() { 124 return fRoot; 125 } 126 127 130 public int hashCode() { 131 return fRoot.hashCode(); 132 } 133 136 public IPath getPath() { 137 return getPackageFragmentRoot().getPath(); 138 } 139 } 140 | Popular Tags |