Determine context package only once.

This commit is contained in:
Erich Schubert 2018-10-25 23:36:17 +02:00
parent 1925d2f1c7
commit aa15be7405
1 changed files with 12 additions and 16 deletions

View File

@ -91,7 +91,7 @@ class ClassGraph {
// used only when generating context class diagrams in UMLDoc, to generate the proper // used only when generating context class diagrams in UMLDoc, to generate the proper
// relative links to other classes in the image map // relative links to other classes in the image map
protected final Doc contextDoc; protected final String contextPackageName;
/** /**
* Create a new ClassGraph. <p>The packages passed as an * Create a new ClassGraph. <p>The packages passed as an
@ -106,7 +106,6 @@ class ClassGraph {
this.optionProvider = optionProvider; this.optionProvider = optionProvider;
this.collectionClassDoc = root.classNamed("java.util.Collection"); this.collectionClassDoc = root.classNamed("java.util.Collection");
this.mapClassDoc = root.classNamed("java.util.Map"); this.mapClassDoc = root.classNamed("java.util.Map");
this.contextDoc = contextDoc;
// to gather the packages containing specified classes, loop thru them and gather // to gather the packages containing specified classes, loop thru them and gather
// package definitions. User root.specifiedPackages is not safe, since the user // package definitions. User root.specifiedPackages is not safe, since the user
@ -117,6 +116,14 @@ class ClassGraph {
rootClassdocs.put(classDoc.qualifiedName(), classDoc); rootClassdocs.put(classDoc.qualifiedName(), classDoc);
} }
// determine the context path, relative to the root
if (contextDoc instanceof ClassDoc)
contextPackageName = ((ClassDoc) contextDoc).containingPackage().name();
else if (contextDoc instanceof PackageDoc)
contextPackageName = ((PackageDoc) contextDoc).name();
else
contextPackageName = null; // Not available
Options opt = optionProvider.getGlobalOptions(); Options opt = optionProvider.getGlobalOptions();
linePrefix = opt.compact ? "" : "\t"; linePrefix = opt.compact ? "" : "\t";
linePostfix = opt.compact ? "" : "\n"; linePostfix = opt.compact ? "" : "\n";
@ -849,20 +856,9 @@ class ClassGraph {
/** Convert the class name into a corresponding URL */ /** Convert the class name into a corresponding URL */
public String classToUrl(ClassDoc cd, boolean rootClass) { public String classToUrl(ClassDoc cd, boolean rootClass) {
// building relative path for context and package diagrams // building relative path for context and package diagrams
if(contextDoc != null && rootClass) { if(contextPackageName != null && rootClass)
// determine the context path, relative to the root return buildRelativePathFromClassNames(contextPackageName, cd.containingPackage().name()) + cd.name() + ".html";
String packageName; return classToUrl(cd.qualifiedName());
if (contextDoc instanceof ClassDoc) {
packageName = ((ClassDoc) contextDoc).containingPackage().name();
} else if (contextDoc instanceof PackageDoc) {
packageName = ((PackageDoc) contextDoc).name();
} else {
return classToUrl(cd.qualifiedName());
}
return buildRelativePathFromClassNames(packageName, cd.containingPackage().name()) + cd.name() + ".html";
} else {
return classToUrl(cd.qualifiedName());
}
} }
private String getPackageName(String className) { private String getPackageName(String className) {