Have relation styles in a single place.

This commit is contained in:
Erich Schubert 2018-10-21 16:56:20 +02:00
parent fe2c0c3df1
commit a4ab6f179a
2 changed files with 24 additions and 24 deletions

View File

@ -80,16 +80,7 @@ class ClassGraph {
this.lower = toString().toLowerCase(); this.lower = toString().toLowerCase();
} }
}; };
public static Map<RelationType, String> associationMap = new HashMap<RelationType, String>();
static {
associationMap.put(RelationType.ASSOC, "arrowhead=none");
associationMap.put(RelationType.NAVASSOC, "arrowhead=open");
associationMap.put(RelationType.HAS, "arrowhead=none, arrowtail=ediamond, dir=both");
associationMap.put(RelationType.NAVHAS, "arrowhead=open, arrowtail=ediamond, dir=both");
associationMap.put(RelationType.COMPOSED, "arrowhead=none, arrowtail=diamond, dir=both");
associationMap.put(RelationType.NAVCOMPOSED, "arrowhead=open, arrowtail=diamond, dir=both");
associationMap.put(RelationType.DEPEND, "arrowhead=open, style=dashed");
}
protected Map<String, ClassInfo> classnames = new HashMap<String, ClassInfo>(); protected Map<String, ClassInfo> classnames = new HashMap<String, ClassInfo>();
protected Set<String> rootClasses; protected Set<String> rootClasses;
protected Map<String, ClassDoc> rootClassdocs = new HashMap<String, ClassDoc>(); protected Map<String, ClassDoc> rootClassdocs = new HashMap<String, ClassDoc>();
@ -558,8 +549,7 @@ class ClassGraph {
ClassDoc to, String toName, String tailLabel, String label, String headLabel) { ClassDoc to, String toName, String tailLabel, String label, String headLabel) {
// print relation // print relation
String edgetype = associationMap.get(rt); w.println("\t// " + fromName + " " + rt.lower + " " + toName);
w.println("\t// " + fromName + " " + rt.toString() + " " + toName);
w.println("\t" + relationNode(from, fromName) + " -> " + relationNode(to, toName) + " [" + w.println("\t" + relationNode(from, fromName) + " -> " + relationNode(to, toName) + " [" +
"taillabel=\"" + tailLabel + "\", " + "taillabel=\"" + tailLabel + "\", " +
((label == null || label.isEmpty()) ? "label=\"\", " : "label=\"" + guillemize(opt, label) + "\", ") + ((label == null || label.isEmpty()) ? "label=\"\", " : "label=\"" + guillemize(opt, label) + "\", ") +
@ -568,7 +558,7 @@ class ClassGraph {
"fontcolor=\"" + opt.edgeFontColor + "\", " + "fontcolor=\"" + opt.edgeFontColor + "\", " +
"fontsize=" + opt.edgeFontSize + ", " + "fontsize=" + opt.edgeFontSize + ", " +
"color=\"" + opt.edgeColor + "\", " + "color=\"" + opt.edgeColor + "\", " +
edgetype + "];" rt.style + "];"
); );
// update relation info // update relation info
@ -624,7 +614,8 @@ class ClassGraph {
!hidden(s.asClassDoc())) { !hidden(s.asClassDoc())) {
ClassDoc sc = s.asClassDoc(); ClassDoc sc = s.asClassDoc();
w.println("\t//" + c + " extends " + s + "\n" + w.println("\t//" + c + " extends " + s + "\n" +
"\t" + relationNode(sc) + " -> " + relationNode(c) + " [dir=back,arrowtail=empty];"); "\t" + relationNode(sc) + " -> " + relationNode(c) +
" [" + RelationType.EXTENDS.style + "];");
getClassInfo(className).addRelation(sc.toString(), RelationType.EXTENDS, RelationDirection.OUT); getClassInfo(className).addRelation(sc.toString(), RelationType.EXTENDS, RelationDirection.OUT);
getClassInfo(sc.toString()).addRelation(className, RelationType.EXTENDS, RelationDirection.IN); getClassInfo(sc.toString()).addRelation(className, RelationType.EXTENDS, RelationDirection.IN);
} }
@ -634,7 +625,7 @@ class ClassGraph {
if (!hidden(tag.text())) { if (!hidden(tag.text())) {
ClassDoc from = c.findClass(tag.text()); ClassDoc from = c.findClass(tag.text());
w.println("\t//" + c + " extends " + tag.text() + "\n" + w.println("\t//" + c + " extends " + tag.text() + "\n" +
"\t" + relationNode(from, tag.text()) + " -> " + relationNode(c) + " [dir=back,arrowtail=empty];"); "\t" + relationNode(from, tag.text()) + " -> " + relationNode(c) + " [" + RelationType.EXTENDS.style + "];");
getClassInfo(className).addRelation(tag.text(), RelationType.EXTENDS, RelationDirection.OUT); getClassInfo(className).addRelation(tag.text(), RelationType.EXTENDS, RelationDirection.OUT);
getClassInfo(tag.text()).addRelation(className, RelationType.EXTENDS, RelationDirection.IN); getClassInfo(tag.text()).addRelation(className, RelationType.EXTENDS, RelationDirection.IN);
} }
@ -642,9 +633,8 @@ class ClassGraph {
for (Type iface : c.interfaceTypes()) { for (Type iface : c.interfaceTypes()) {
ClassDoc ic = iface.asClassDoc(); ClassDoc ic = iface.asClassDoc();
if (!hidden(ic)) { if (!hidden(ic)) {
w.println("\t//" + c + " implements " + ic + "\n\t" + w.println("\t//" + c + " implements " + ic + "\n\t" + relationNode(ic) + " -> " + relationNode(c)
relationNode(ic) + " -> " + relationNode(c) + " [dir=back,arrowtail=empty,style=dashed];" + " [" + RelationType.IMPLEMENTS.style + "];");
);
getClassInfo(className).addRelation(ic.toString(), RelationType.IMPLEMENTS, RelationDirection.OUT); getClassInfo(className).addRelation(ic.toString(), RelationType.IMPLEMENTS, RelationDirection.OUT);
getClassInfo(ic.toString()).addRelation(className, RelationType.IMPLEMENTS, RelationDirection.IN); getClassInfo(ic.toString()).addRelation(className, RelationType.IMPLEMENTS, RelationDirection.IN);
} }

View File

@ -1,16 +1,26 @@
package org.umlgraph.doclet; package org.umlgraph.doclet;
/** /**
* The type of relation that links two entities * The type of relation that links two entities, and the graphviz format
* @author wolf
* *
* @author Erich Schubert
*/ */
public enum RelationType { public enum RelationType {
ASSOC(), NAVASSOC(), HAS(), NAVHAS(), COMPOSED(), NAVCOMPOSED(), DEPEND(), EXTENDS(), IMPLEMENTS(); ASSOC("arrowhead=none"), //
NAVASSOC("arrowhead=open"), //
HAS("arrowhead=none, arrowtail=ediamond, dir=both"), //
NAVHAS("arrowhead=open, arrowtail=ediamond, dir=both"), //
COMPOSED("arrowhead=none, arrowtail=diamond, dir=both"), //
NAVCOMPOSED("arrowhead=open, arrowtail=diamond, dir=both"), //
DEPEND("arrowhead=open, style=dashed"), //
EXTENDS("arrowtail=empty, dir=back"), //
IMPLEMENTS("arrowtail=empty, dir=back, style=dashed");
public final String lower; public final String lower, style;
private RelationType() { /** Enum constructors must be private */
this.lower = toString().toLowerCase(); private RelationType(String style) {
this.lower = toString().toLowerCase();
this.style = style;
} }
} }