mirror of https://github.com/dspinellis/UMLGraph
More StringUtil functionality.
This commit is contained in:
parent
08b8976076
commit
1925d2f1c7
|
|
@ -25,7 +25,7 @@ import static org.umlgraph.doclet.StringUtil.guillemize;
|
||||||
import static org.umlgraph.doclet.StringUtil.htmlNewline;
|
import static org.umlgraph.doclet.StringUtil.htmlNewline;
|
||||||
import static org.umlgraph.doclet.StringUtil.removeTemplate;
|
import static org.umlgraph.doclet.StringUtil.removeTemplate;
|
||||||
import static org.umlgraph.doclet.StringUtil.tokenize;
|
import static org.umlgraph.doclet.StringUtil.tokenize;
|
||||||
|
import static org.umlgraph.doclet.StringUtil.buildRelativePathFromClassNames;
|
||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
|
@ -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 Doc contextDoc;
|
protected final Doc contextDoc;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new ClassGraph. <p>The packages passed as an
|
* Create a new ClassGraph. <p>The packages passed as an
|
||||||
|
|
@ -114,17 +114,12 @@ class ClassGraph {
|
||||||
rootClasses = new HashSet<String>();
|
rootClasses = new HashSet<String>();
|
||||||
for (ClassDoc classDoc : root.classes()) {
|
for (ClassDoc classDoc : root.classes()) {
|
||||||
rootClasses.add(classDoc.qualifiedName());
|
rootClasses.add(classDoc.qualifiedName());
|
||||||
rootClassdocs.put(classDoc.qualifiedName(), classDoc);
|
rootClassdocs.put(classDoc.qualifiedName(), classDoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
Options opt = optionProvider.getGlobalOptions();
|
Options opt = optionProvider.getGlobalOptions();
|
||||||
if (opt.compact) {
|
linePrefix = opt.compact ? "" : "\t";
|
||||||
linePrefix = "";
|
linePostfix = opt.compact ? "" : "\n";
|
||||||
linePostfix = "";
|
|
||||||
} else {
|
|
||||||
linePrefix = "\t";
|
|
||||||
linePostfix = "\n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -864,39 +859,12 @@ class ClassGraph {
|
||||||
} else {
|
} else {
|
||||||
return classToUrl(cd.qualifiedName());
|
return classToUrl(cd.qualifiedName());
|
||||||
}
|
}
|
||||||
return buildRelativePath(packageName, cd.containingPackage().name()) + cd.name() + ".html";
|
return buildRelativePathFromClassNames(packageName, cd.containingPackage().name()) + cd.name() + ".html";
|
||||||
} else {
|
} else {
|
||||||
return classToUrl(cd.qualifiedName());
|
return classToUrl(cd.qualifiedName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static String buildRelativePath(String contextPackageName, String classPackageName) {
|
|
||||||
// path, relative to the root, of the destination class
|
|
||||||
String[] contextClassPath = contextPackageName.split("\\.");
|
|
||||||
String[] currClassPath = classPackageName.split("\\.");
|
|
||||||
|
|
||||||
// compute relative path between the context and the destination
|
|
||||||
// ... first, compute common part
|
|
||||||
int i = 0;
|
|
||||||
while (i < contextClassPath.length && i < currClassPath.length
|
|
||||||
&& contextClassPath[i].equals(currClassPath[i]))
|
|
||||||
i++;
|
|
||||||
// ... go up with ".." to reach the common root
|
|
||||||
StringBuilder buf = new StringBuilder();
|
|
||||||
if (i == contextClassPath.length) {
|
|
||||||
buf.append('.').append(FILE_SEPARATOR);
|
|
||||||
} else {
|
|
||||||
for (int j = i; j < contextClassPath.length; j++) {
|
|
||||||
buf.append("..").append(FILE_SEPARATOR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// ... go down from the common root to the destination
|
|
||||||
for (int j = i; j < currClassPath.length; j++) {
|
|
||||||
buf.append(currClassPath[j]).append(FILE_SEPARATOR);
|
|
||||||
}
|
|
||||||
return buf.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getPackageName(String className) {
|
private String getPackageName(String className) {
|
||||||
if (this.rootClassdocs.get(className) == null) {
|
if (this.rootClassdocs.get(className) == null) {
|
||||||
int idx = className.lastIndexOf('.');
|
int idx = className.lastIndexOf('.');
|
||||||
|
|
@ -920,7 +888,7 @@ class ClassGraph {
|
||||||
String docRoot = mapApiDocRoot(className);
|
String docRoot = mapApiDocRoot(className);
|
||||||
if (docRoot == null)
|
if (docRoot == null)
|
||||||
return null;
|
return null;
|
||||||
return new StringBuilder(docRoot) //
|
return new StringBuilder(250).append(docRoot) //
|
||||||
.append(getPackageName(className).replace('.', FILE_SEPARATOR)) //
|
.append(getPackageName(className).replace('.', FILE_SEPARATOR)) //
|
||||||
.append(FILE_SEPARATOR) //
|
.append(FILE_SEPARATOR) //
|
||||||
.append(getUnqualifiedName(className)) //
|
.append(getUnqualifiedName(className)) //
|
||||||
|
|
|
||||||
|
|
@ -164,4 +164,24 @@ class StringUtil {
|
||||||
}
|
}
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String buildRelativePathFromClassNames(String contextPackageName, String classPackageName) {
|
||||||
|
// path, relative to the root, of the destination class
|
||||||
|
String[] contextClassPath = contextPackageName.split("\\.");
|
||||||
|
String[] currClassPath = classPackageName.split("\\.");
|
||||||
|
|
||||||
|
// compute relative path between the context and the destination
|
||||||
|
// ... first, compute common part
|
||||||
|
int i = 0, e = Math.min(contextClassPath.length, currClassPath.length);
|
||||||
|
while (i < e && contextClassPath[i].equals(currClassPath[i]))
|
||||||
|
i++;
|
||||||
|
// ... go up with ".." to reach the common root
|
||||||
|
StringBuilder buf = new StringBuilder(classPackageName.length());
|
||||||
|
for (int j = i; j < contextClassPath.length; j++)
|
||||||
|
buf.append("../");
|
||||||
|
// ... go down from the common root to the destination
|
||||||
|
for (int j = i; j < currClassPath.length; j++)
|
||||||
|
buf.append(currClassPath[j]).append('/'); // Always use HTML seperators
|
||||||
|
return buf.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue