this.lastPkgFragmentRoot= root;
this.packageHandles= new HashtableOfArrayToObject(5);
}
// create handle
String classFilePath= resourcePath.substring(separatorIndex + 1);
String[] simpleNames = new Path(classFilePath).segments();
String[] pkgName;
int length = simpleNames.length-1;
if (length > 0) {
pkgName = new String[length];
System.arraycopy(simpleNames, 0, pkgName, 0, length);
} else {
pkgName = CharOperation.NO_STRINGS;
}
IPackageFragment pkgFragment= (IPackageFragment) this.packageHandles.get(pkgName);
if (pkgFragment == null) {
pkgFragment= ((PackageFragmentRoot) this.lastPkgFragmentRoot).getPackageFragment(pkgName);
this.packageHandles.put(pkgName, pkgFragment);
}
IClassFile classFile= pkgFragment.getClassFile(simpleNames[length]);
return (Openable) classFile;
} else {
// path to a file in a directory
// Optimization: cache package fragment root handle and package handles
int rootPathLength = -1;
if (this.lastPkgFragmentRootPath == null
|| !(resourcePath.startsWith(this.lastPkgFragmentRootPath)
&& (rootPathLength = this.lastPkgFragmentRootPath.length()) > 0
&& resourcePath.charAt(rootPathLength) == '/')) {
IPackageFragmentRoot root= this.getPkgFragmentRoot(resourcePath);
if (root == null)
return null; // match is outside classpath
this.lastPkgFragmentRoot = root;
this.lastPkgFragmentRootPath = this.lastPkgFragmentRoot.getPath().toString();
this.packageHandles = new HashtableOfArrayToObject(5);
}
// create handle
resourcePath = resourcePath.substring(this.lastPkgFragmentRootPath.length() + 1);
String[] simpleNames = new Path(resourcePath).segments();
String[] pkgName;
int length = simpleNames.length-1;
if (length > 0) {
pkgName = new String[length];
System.arraycopy(simpleNames, 0, pkgName, 0, length);