in maven-jxr/src/main/java/org/apache/maven/jxr/JavaCodeTransform.java [1136:1205]
private String importFilter(String line) {
int start = -1;
/*
* Used for determining if this is a package declaration. If it is then we can make some additional assumptions:
* - that this isn't a Class import so the full String is valid - that it WILL be on the disk since this is
* based on the current - file.
*/
boolean isPackage = line.trim().startsWith("package ");
boolean isImport = line.trim().startsWith("import ");
if (isImport || isPackage) {
start = line.trim().indexOf(' ');
}
if (start != -1) {
// filter out this packagename...
String pkg = line.substring(start).trim();
// specify the classname of this import if any.
String classname = null;
if (pkg.contains(".*")) {
pkg = pkg.replace(".*", "");
} else if (!isPackage) {
// this is an explicit Class import
String packageLine = pkg;
// This catches a boundary problem where you have something like:
//
// Foo foo = FooMaster.getFooInstance().
// danceLittleFoo();
//
// This breaks Jxr and won't be a problem when we hook
// in the real parser.
int a = packageLine.lastIndexOf('.') + 1;
int b = packageLine.length() - 1;
if (a > b + 1) {
classname = packageLine.substring(packageLine.lastIndexOf('.') + 1, packageLine.length() - 1);
int end = pkg.lastIndexOf('.');
if (end == -1) {
end = pkg.length() - 1;
}
pkg = pkg.substring(0, end);
}
}
pkg = pkg.replace(";", "");
String pkgHREF = getHREF(pkg);
// if this package is within the PackageManager then you can create an HREF for it.
if (packageManager.getPackageType(pkg) != null || isPackage) {
// Create an HREF for explicit classname imports
if (classname != null) {
line = line.replace(
classname, "<a href=\"" + pkgHREF + '/' + classname + ".html" + "\">" + classname + "</a>");
}
// now replace the given package with a href
line = line.replace(pkg, "<a href=\"" + pkgHREF + '/' + DirectoryIndexer.INDEX + "\">" + pkg + "</a>");
}
}
return line;
}