// If that fails, determine the URL for the class itself.
// The URL will be of one of the following forms,
// so there are a few good places to consider looking for the plugin.properties.
//
// For a plugin.xml with runtime="common.jar":
// jar:file:/D:/sandbox/unpackage1-3.1M7/eclipse/plugins/org.eclipse.emf.common/common.jar!/org/eclipse/common/CommonPlugin.class
//
// For a plugin.xml with runtime="runtime/common.jar":
// jar:file:/D:/sandbox/unpackage1-3.1M7/eclipse/plugins/org.eclipse.emf.common/runtime/common.jar!/org/eclipse/common/CommonPlugin.class
//
// For a plugin.xml with runtime="." where the plugin is jarred:
// jar:file:/D:/sandbox/unpackage1-3.1M7/eclipse/plugins/org.eclipse.emf.common.jar!/org/eclipse/common/CommonPlugin.class
//
// For a plugin.xml with runtime="." where the plugin is not jarred.
// file:/D:/sandbox/unpackage1-3.1M7/eclipse/plugins/org.eclipse.emf.common/org/eclipse/emf/common/CommonPlugin.class
//
// Running in PDE with bin on classpath:
// file:/D:/sandbox/unpackage1-3.1M7/eclipse/plugins/org.eclipse.emf.common/bin/org/eclipse/emf/common/CommonPlugin.class
//
String className = theClass.getName();
int index = className.lastIndexOf(".");
URL classURL = theClass.getResource((index == -1 ? className: className.substring(index + 1)) + ".class");
URI uri = URI.createURI(classURL.toString());
// Trim off the segments corresponding to the package nesting.
//
int count = 1;
for (int i = 0; (i = className.indexOf('.', i)) != -1; ++i) {
++count;
}
uri = uri.trimSegments(count);
|