mirror of https://github.com/dspinellis/UMLGraph
Improve class info handling.
This commit is contained in:
parent
c7d8648352
commit
dc18c503e9
|
|
@ -312,26 +312,17 @@ class ClassGraph {
|
|||
|
||||
/** Return true if c has a @hidden tag associated with it */
|
||||
private boolean hidden(ProgramElementDoc c) {
|
||||
Tag tags[] = c.tags("hidden");
|
||||
if (tags.length > 0)
|
||||
return true;
|
||||
tags = c.tags("view");
|
||||
if (tags.length > 0)
|
||||
return true;
|
||||
Options opt;
|
||||
if(c instanceof ClassDoc)
|
||||
opt = optionProvider.getOptionsFor((ClassDoc) c);
|
||||
else
|
||||
opt = optionProvider.getOptionsFor(c.containingClass());
|
||||
return opt.matchesHideExpression(c.toString());
|
||||
return c.tags("hidden").length > 0 || c.tags("view").length > 0 || //
|
||||
optionProvider.getOptionsFor(c instanceof ClassDoc ? (ClassDoc) c : c.containingClass()) //
|
||||
.matchesHideExpression(c.toString());
|
||||
}
|
||||
|
||||
protected ClassInfo getClassInfo(String className) {
|
||||
return classnames.get(removeTemplate(className));
|
||||
}
|
||||
|
||||
private ClassInfo newClassInfo(String className, boolean printed, boolean hidden) {
|
||||
ClassInfo ci = new ClassInfo(printed, hidden);
|
||||
private ClassInfo newClassInfo(String className, boolean hidden) {
|
||||
ClassInfo ci = new ClassInfo(hidden);
|
||||
classnames.put(removeTemplate(className), ci);
|
||||
return ci;
|
||||
}
|
||||
|
|
@ -352,21 +343,16 @@ class ClassGraph {
|
|||
* relative links in diagrams for UMLDoc
|
||||
*/
|
||||
public String printClass(ClassDoc c, boolean rootClass) {
|
||||
ClassInfo ci;
|
||||
boolean toPrint;
|
||||
Options opt = optionProvider.getOptionsFor(c);
|
||||
|
||||
String className = c.toString();
|
||||
if ((ci = getClassInfo(className)) != null)
|
||||
toPrint = !ci.nodePrinted;
|
||||
else {
|
||||
toPrint = true;
|
||||
ci = newClassInfo(className, true, hidden(c));
|
||||
}
|
||||
if (toPrint && !hidden(c) && (!c.isEnum() || opt.showEnumerations)) {
|
||||
ClassInfo ci = getClassInfo(className);
|
||||
ci = ci != null ? ci : newClassInfo(className, hidden(c));
|
||||
if(ci.nodePrinted || ci.hidden)
|
||||
return ci.name;
|
||||
Options opt = optionProvider.getOptionsFor(c);
|
||||
if (c.isEnum() && !opt.showEnumerations)
|
||||
return ci.name;
|
||||
// Associate classname's alias
|
||||
String r = className;
|
||||
w.println("\t// " + r);
|
||||
w.println("\t// " + className);
|
||||
// Create label
|
||||
w.print("\t" + ci.name + " [label=");
|
||||
|
||||
|
|
@ -385,7 +371,7 @@ class ClassGraph {
|
|||
tableLine(Align.CENTER, guilWrap(opt, "enumeration"));
|
||||
stereotype(opt, c, Align.CENTER);
|
||||
Font font = c.isAbstract() && !c.isInterface() ? Font.CLASS_ABSTRACT : Font.CLASS;
|
||||
String qualifiedName = qualifiedName(opt, r);
|
||||
String qualifiedName = qualifiedName(opt, className);
|
||||
int startTemplate = qualifiedName.indexOf('<');
|
||||
int idx = qualifiedName.lastIndexOf('.', startTemplate < 0 ? qualifiedName.length() - 1 : startTemplate);
|
||||
if (opt.showComment)
|
||||
|
|
@ -401,6 +387,11 @@ class ClassGraph {
|
|||
tagvalue(opt, c);
|
||||
firstInnerTableEnd(opt);
|
||||
|
||||
/*
|
||||
* Warning: The boolean expressions guarding innerTableStart()
|
||||
* in this block, should match those in the code block above
|
||||
* marked: "Calculate the number of innerTable rows we will emmit"
|
||||
*/
|
||||
if (showMembers) {
|
||||
if (opt.showAttributes) {
|
||||
innerTableStart();
|
||||
|
|
@ -467,24 +458,6 @@ class ClassGraph {
|
|||
ni++;
|
||||
}
|
||||
ci.nodePrinted = true;
|
||||
}
|
||||
return ci.name;
|
||||
}
|
||||
|
||||
private String getNodeName(ClassDoc c) {
|
||||
String className = c.toString();
|
||||
ClassInfo ci = getClassInfo(className);
|
||||
if (ci == null)
|
||||
ci = newClassInfo(className, false, hidden(c));
|
||||
return ci.name;
|
||||
}
|
||||
|
||||
/** Return a class's internal name */
|
||||
private String getNodeName(String c) {
|
||||
ClassInfo ci = getClassInfo(c);
|
||||
|
||||
if (ci == null)
|
||||
ci = newClassInfo(c, false, false);
|
||||
return ci.name;
|
||||
}
|
||||
|
||||
|
|
@ -564,7 +537,10 @@ class ClassGraph {
|
|||
* whose outline is rendered through an inner table.
|
||||
*/
|
||||
private String relationNode(ClassDoc c) {
|
||||
return getNodeName(c) + optionProvider.getOptionsFor(c).shape.landingPort();
|
||||
String className = c.toString();
|
||||
ClassInfo ci = getClassInfo(className);
|
||||
return (ci != null ? ci : newClassInfo(className, hidden(c))).name //
|
||||
+ optionProvider.getOptionsFor(c).shape.landingPort();
|
||||
}
|
||||
|
||||
/** Return the full name of a relation's node c.
|
||||
|
|
@ -575,7 +551,9 @@ class ClassGraph {
|
|||
*/
|
||||
private String relationNode(ClassDoc c, String cName) {
|
||||
Options opt = c == null ? optionProvider.getOptionsFor(cName) : optionProvider.getOptionsFor(c);
|
||||
return getNodeName(cName) + opt.shape.landingPort();
|
||||
ClassInfo ci = getClassInfo(cName);
|
||||
return (ci != null ? ci : newClassInfo(cName, false)).name //
|
||||
+ opt.shape.landingPort();
|
||||
}
|
||||
|
||||
/** Print a class's relations */
|
||||
|
|
@ -584,14 +562,10 @@ class ClassGraph {
|
|||
if (hidden(c) || c.name().equals("")) // avoid phantom classes, they may pop up when the source uses annotations
|
||||
return;
|
||||
String className = c.toString();
|
||||
|
||||
// Print generalization (through the Java superclass)
|
||||
Type s = c.superclassType();
|
||||
if (s != null &&
|
||||
!s.toString().equals("java.lang.Object") &&
|
||||
!c.isEnum() &&
|
||||
!hidden(s.asClassDoc())) {
|
||||
ClassDoc sc = s.asClassDoc();
|
||||
ClassDoc sc = s != null && !s.qualifiedTypeName().equals(Object.class.getName()) ? s.asClassDoc() : null;
|
||||
if (sc != null && !c.isEnum() && !hidden(sc)) {
|
||||
w.println("\t//" + c + " extends " + s + "\n" +
|
||||
"\t" + relationNode(sc) + " -> " + relationNode(c) +
|
||||
" [" + RelationType.EXTENDS.style + "];");
|
||||
|
|
|
|||
|
|
@ -43,8 +43,7 @@ class ClassInfo {
|
|||
*/
|
||||
Map<String, RelationPattern> relatedClasses = new HashMap<String, RelationPattern>();
|
||||
|
||||
ClassInfo(boolean p, boolean h) {
|
||||
nodePrinted = p;
|
||||
ClassInfo(boolean h) {
|
||||
hidden = h;
|
||||
name = "c" + classNumber;
|
||||
classNumber++;
|
||||
|
|
|
|||
|
|
@ -97,27 +97,24 @@ public class ContextMatcher implements ClassMatcher {
|
|||
|
||||
/**
|
||||
* Adds the specified class to the internal class graph along with its
|
||||
* relations and depencies, eventually inferring them, according to the
|
||||
* relations and dependencies, eventually inferring them, according to the
|
||||
* Options specified for this matcher
|
||||
* @param cd
|
||||
*/
|
||||
private void addToGraph(ClassDoc cd) {
|
||||
// avoid adding twice the same class, but don't rely on cg.getClassInfo
|
||||
// since there
|
||||
// are other ways to add a classInfor than printing the class
|
||||
// since there are other ways to add a classInfor than printing the class
|
||||
if (visited.contains(cd.toString()))
|
||||
return;
|
||||
|
||||
visited.add(cd.toString());
|
||||
cg.printClass(cd, false);
|
||||
cg.printRelations(cd);
|
||||
if (opt.inferRelationships) {
|
||||
if (opt.inferRelationships)
|
||||
cg.printInferredRelations(cd);
|
||||
}
|
||||
if (opt.inferDependencies) {
|
||||
if (opt.inferDependencies)
|
||||
cg.printInferredDependencies(cd);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.umlgraph.doclet.ClassMatcher#matches(com.sun.javadoc.ClassDoc)
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ public class ContextView implements OptionProvider {
|
|||
this.centerOptions.nodeFillColor = "lemonChiffon";
|
||||
this.centerOptions.showQualified = false;
|
||||
|
||||
this.matcher = new ContextMatcher(root, Pattern.compile(cd.qualifiedName()),
|
||||
this.matcher = new ContextMatcher(root, Pattern.compile(Pattern.quote(cd.toString())),
|
||||
myGlobalOptions, true);
|
||||
|
||||
}
|
||||
|
|
@ -62,7 +62,7 @@ public class ContextView implements OptionProvider {
|
|||
String outputPath = cd.containingPackage().name().replace('.', '/') + "/" + cd.name()
|
||||
+ ".dot";
|
||||
this.myGlobalOptions.setOption(new String[] { "output", outputPath });
|
||||
matcher.setContextCenter(Pattern.compile(cd.toString()));
|
||||
matcher.setContextCenter(Pattern.compile(Pattern.quote(cd.toString())));
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue