diff --git a/src/main/java/org/umlgraph/doclet/ClassGraph.java b/src/main/java/org/umlgraph/doclet/ClassGraph.java index c6f0dfb..e6255b1 100644 --- a/src/main/java/org/umlgraph/doclet/ClassGraph.java +++ b/src/main/java/org/umlgraph/doclet/ClassGraph.java @@ -72,7 +72,13 @@ class ClassGraph { NORMAL, ABSTRACT, CLASS, CLASS_ABSTRACT, TAG, PACKAGE } enum Align { - LEFT, CENTER, RIGHT + LEFT, CENTER, RIGHT; + + public final String lower; + + private Align() { + this.lower = toString().toLowerCase(); + } }; public static Map associationMap = new HashMap(); static { @@ -186,50 +192,41 @@ class ClassGraph { /** Print the method parameter p */ private String parameter(Options opt, Parameter p[]) { - String par = ""; + StringBuilder par = new StringBuilder(1000); for (int i = 0; i < p.length; i++) { - par += p[i].name() + typeAnnotation(opt, p[i].type()); + par.append(p[i].name() + typeAnnotation(opt, p[i].type())); if (i + 1 < p.length) - par += ", "; + par.append(", "); } - return par; + return par.toString(); } /** Print a a basic type t */ private String type(Options opt, Type t, boolean generics) { - String type; - if (generics ? opt.showQualifiedGenerics : opt.showQualified) - type = t.qualifiedTypeName(); - else - type = t.typeName(); - type += typeParameters(opt, t.asParameterizedType()); - return type; + return ((generics ? opt.showQualifiedGenerics : opt.showQualified) ?// + t.qualifiedTypeName() : t.typeName()) // + + typeParameters(opt, t.asParameterizedType()); } /** Print the parameters of the parameterized type t */ private String typeParameters(Options opt, ParameterizedType t) { - String tp = ""; if (t == null) - return tp; + return ""; + StringBuffer tp = new StringBuffer(1000).append("<"); Type args[] = t.typeArguments(); - tp += "<"; for (int i = 0; i < args.length; i++) { - tp += type(opt, args[i], true); + tp.append(type(opt, args[i], true)); if (i != args.length - 1) - tp += ", "; + tp.append(", "); } - tp += ">"; - return tp; + return tp.append(">").toString(); } /** Annotate an field/argument with its type t */ private String typeAnnotation(Options opt, Type t) { if (t.typeName().equals("void")) return ""; - String ta = " : "; - ta += type(opt, t, false); - ta += t.dimension(); - return ta; + return " : " + type(opt, t, false) + t.dimension(); } /** Print the class's attributes fd */ @@ -237,9 +234,8 @@ class ClassGraph { for (FieldDoc f : fd) { if (hidden(f)) continue; - String att; stereotype(opt, f, Align.LEFT); - att = visibility(opt, f) + f.name(); + String att = visibility(opt, f) + f.name(); if (opt.showType) att += typeAnnotation(opt, f.type()); tableLine(Align.LEFT, att); @@ -373,11 +369,7 @@ class ClassGraph { /** Return true if the class name is associated to an hidden class or matches a hide expression */ private boolean hidden(String s) { ClassInfo ci = getClassInfo(s); - Options opt = optionProvider.getOptionsFor(s); - if(ci != null) - return ci.hidden || opt.matchesHideExpression(s); - else - return opt.matchesHideExpression(s); + return (ci != null && ci.hidden) || optionProvider.getOptionsFor(s).matchesHideExpression(s); } @@ -603,9 +595,7 @@ class ClassGraph { * whose outline is rendered through an inner table. */ private String relationNode(ClassDoc c) { - Options opt = optionProvider.getOptionsFor(c); - String name = getNodeName(c); - return name + opt.shape.landingPort(); + return getNodeName(c) + optionProvider.getOptionsFor(c).shape.landingPort(); } /** Return the full name of a relation's node c. @@ -615,13 +605,8 @@ class ClassGraph { * @param cName the node's class name */ private String relationNode(ClassDoc c, String cName) { - Options opt; - if (c == null) - opt = optionProvider.getOptionsFor(cName); - else - opt = optionProvider.getOptionsFor(c); - String name = getNodeName(cName); - return name + opt.shape.landingPort(); + Options opt = c == null ? optionProvider.getOptionsFor(cName) : optionProvider.getOptionsFor(c); + return getNodeName(cName) + opt.shape.landingPort(); } /** Print a class's relations */ @@ -930,7 +915,7 @@ class ClassGraph { // ... go up with ".." to reach the common root StringBuilder buf = new StringBuilder(); if (i == contextClassPath.length) { - buf.append(".").append(FILE_SEPARATOR); + buf.append('.').append(FILE_SEPARATOR); } else { for (int j = i; j < contextClassPath.length; j++) { buf.append("..").append(FILE_SEPARATOR); @@ -963,16 +948,14 @@ class ClassGraph { /** Convert the class name into a corresponding URL */ public String classToUrl(String className) { - String docRoot = mapApiDocRoot(className); - if (docRoot != null) { - StringBuilder buf = new StringBuilder(docRoot); - buf.append(getPackageName(className).replace('.', FILE_SEPARATOR) + FILE_SEPARATOR); - buf.append(getUnqualifiedName(className)); - buf.append(".html"); - return buf.toString(); - } else { - return null; - } + String docRoot = mapApiDocRoot(className); + if (docRoot == null) + return null; + return new StringBuilder(docRoot) // + .append(getPackageName(className).replace('.', FILE_SEPARATOR)) // + .append(FILE_SEPARATOR) // + .append(getUnqualifiedName(className)) // + .append(".html").toString(); } /** @@ -981,15 +964,11 @@ class ClassGraph { * the final diagram to the associated JavaDoc page. */ private String mapApiDocRoot(String className) { - String root; /* If no packages are specified, we use apiDocRoot for all of them. */ - if (rootClasses.contains(className)) { - root = optionProvider.getGlobalOptions().apiDocRoot; - } else { - Options globalOptions = optionProvider.getGlobalOptions(); - root = globalOptions.getApiDocRoot(className); - } - return root; + if (rootClasses.contains(className)) + return optionProvider.getGlobalOptions().apiDocRoot; + else + return optionProvider.getGlobalOptions().getApiDocRoot(className); } @@ -1004,11 +983,7 @@ class ClassGraph { else { // prepare output file. Use the output file name as a full path unless the output // directory is specified - File file; - if (opt.outputDirectory != null) - file = new File(opt.outputDirectory, opt.outputFileName); - else - file = new File(opt.outputFileName); + File file = new File(opt.outputDirectory, opt.outputFileName); // make sure the output directory are there, otherwise create them if (file.getParentFile() != null && !file.getParentFile().exists()) @@ -1049,13 +1024,8 @@ class ClassGraph { } private void externalTableStart(Options opt, String name, String url) { - String bgcolor = ""; - if (opt.nodeFillColor != null) - bgcolor = " bgcolor=\""+ opt.nodeFillColor + "\""; - String href = ""; - if (url != null) - href = " href=\"" + url + "\" target=\"_parent\""; - + String bgcolor = opt.nodeFillColor == null ? "" : (" bgcolor=\"" + opt.nodeFillColor + "\""); + String href = url == null ? "" : (" href=\"" + url + "\" target=\"_parent\""); w.print("<" + linePostfix); @@ -1094,27 +1064,13 @@ class ClassGraph { private void tableLine(Align align, String text) { tableLine(align, text, null, Font.NORMAL); } - - private void tableLine(Align align, String text, Options opt, Font font) { - String open; - String close = ""; - String prefix = linePrefix + linePrefix + linePrefix; - String alignText; - if(align == Align.CENTER) - alignText = "center"; - else if(align == Align.LEFT) - alignText = "left"; - else if(align == Align.RIGHT) - alignText = "right"; - else - throw new RuntimeException("Unknown alignement type " + align); - - text = fontWrap(" " + text + " ", opt, font); - open = "" + linePostfix); } - + /** * Wraps the text with the appropriate font according to the specified font type * @param opt @@ -1128,12 +1084,9 @@ class ClassGraph { } else if(font == Font.CLASS) { return fontWrap(text, opt.nodeFontClassName, opt.nodeFontClassSize); } else if(font == Font.CLASS_ABSTRACT) { - String name; - if(opt.nodeFontClassAbstractName == null) - name = opt.nodeFontAbstractName; - else - name = opt.nodeFontClassAbstractName; - return fontWrap(text, name, opt.nodeFontClassSize); + return fontWrap(text, + opt.nodeFontClassAbstractName == null ? opt.nodeFontAbstractName : opt.nodeFontClassAbstractName, + opt.nodeFontClassSize); } else if(font == Font.PACKAGE) { return fontWrap(text, opt.nodeFontPackageName, opt.nodeFontPackageSize); } else if(font == Font.TAG) { diff --git a/src/main/java/org/umlgraph/doclet/ClassInfo.java b/src/main/java/org/umlgraph/doclet/ClassInfo.java index 75727cf..28c7c4a 100644 --- a/src/main/java/org/umlgraph/doclet/ClassInfo.java +++ b/src/main/java/org/umlgraph/doclet/ClassInfo.java @@ -20,7 +20,6 @@ package org.umlgraph.doclet; import java.util.HashMap; -import java.util.List; import java.util.Map; /** @@ -47,7 +46,7 @@ class ClassInfo { ClassInfo(boolean p, boolean h) { nodePrinted = p; hidden = h; - name = "c" + (new Integer(classNumber)).toString(); + name = "c" + classNumber; classNumber++; } diff --git a/src/main/java/org/umlgraph/doclet/ContextView.java b/src/main/java/org/umlgraph/doclet/ContextView.java index 6d6d03e..a20e857 100755 --- a/src/main/java/org/umlgraph/doclet/ContextView.java +++ b/src/main/java/org/umlgraph/doclet/ContextView.java @@ -91,7 +91,7 @@ public class ContextView implements OptionProvider { } public Options getOptionsFor(String name) { - Options opt; + Options opt; if (!matcher.matches(name)) opt = hideOptions; else if (name.equals(cd.name())) diff --git a/src/main/java/org/umlgraph/doclet/InterfaceMatcher.java b/src/main/java/org/umlgraph/doclet/InterfaceMatcher.java index 6841cc0..6c63b98 100644 --- a/src/main/java/org/umlgraph/doclet/InterfaceMatcher.java +++ b/src/main/java/org/umlgraph/doclet/InterfaceMatcher.java @@ -26,23 +26,17 @@ public class InterfaceMatcher implements ClassMatcher { // for each interface, recurse, since classes and interfaces // are treated the same in the doclet API - for (ClassDoc iface : cd.interfaces()) { + for (ClassDoc iface : cd.interfaces()) if(matches(iface)) return true; - } // recurse on supeclass, if available - if(cd.superclass() != null) - return matches(cd.superclass()); - - return false; + return cd.superclass() == null ? false : matches(cd.superclass()); } public boolean matches(String name) { ClassDoc cd = root.classNamed(name); - if(cd == null) - return false; - return matches(cd); + return cd == null ? false : matches(cd); } } diff --git a/src/main/java/org/umlgraph/doclet/Options.java b/src/main/java/org/umlgraph/doclet/Options.java index 1109c62..8412964 100644 --- a/src/main/java/org/umlgraph/doclet/Options.java +++ b/src/main/java/org/umlgraph/doclet/Options.java @@ -288,10 +288,10 @@ public class Options implements Cloneable, OptionProvider { showType = true; } else if (opt[0].equals("-!types")) { showType = false; - } else if(opt[0].equals("-autoSize")) { - autoSize = true; - } else if (opt[0].equals("-!autoSize")) { - autoSize = false; + } else if(opt[0].equals("-autoSize")) { + autoSize = true; + } else if (opt[0].equals("-!autoSize")) { + autoSize = false; } else if(opt[0].equals("-commentname")) { showComment = true; } else if (opt[0].equals("-!commentname")) { @@ -589,11 +589,10 @@ public class Options implements Cloneable, OptionProvider { userMap.load(is); for (Map.Entry mapEntry : userMap.entrySet()) { try { - Pattern regex = Pattern.compile((String) mapEntry.getKey()); String thisRoot = (String) mapEntry.getValue(); if (thisRoot != null) { thisRoot = fixApiDocRoot(thisRoot); - apiDocMap.put(regex, thisRoot); + apiDocMap.put(Pattern.compile((String) mapEntry.getKey()), thisRoot); } else { System.err.println("No URL for pattern " + mapEntry.getKey()); } @@ -614,7 +613,7 @@ public class Options implements Cloneable, OptionProvider { * match the class name against the regular expressions specified in the * apiDocMap; if a match is found, the associated URL * will be returned. - * + *

* NOTE: The match order of the match attempts is the one specified by the * constructor of the api doc root, so it depends on the order of "-link" and "-apiDocMap" * parameters. @@ -624,9 +623,7 @@ public class Options implements Cloneable, OptionProvider { apiDocMap.put(Pattern.compile(".*"), DEFAULT_EXTERNAL_APIDOC); for (Map.Entry mapEntry : apiDocMap.entrySet()) { - Pattern regex = mapEntry.getKey(); - Matcher matcher = regex.matcher(className); - if (matcher.matches()) + if (mapEntry.getKey().matcher(className).matches()) return mapEntry.getValue(); } return null; @@ -634,16 +631,15 @@ public class Options implements Cloneable, OptionProvider { /** Trim and append a file separator to the string */ private String fixApiDocRoot(String str) { - String fixed = null; - if (str != null) { - fixed = str.trim(); - if (fixed.length() > 0) { - if (!File.separator.equals("/")) - fixed = fixed.replace(File.separator.charAt(0), '/'); - if (!fixed.endsWith("/")) - fixed = fixed + "/"; - } - } + if (str == null) + return null; + String fixed = str.trim(); + if (fixed.isEmpty()) + return ""; + if (File.separatorChar != '/') + fixed = fixed.replace(File.separatorChar, '/'); + if (!fixed.endsWith("/")) + fixed = fixed + "/"; return fixed; } @@ -678,13 +674,8 @@ public class Options implements Cloneable, OptionProvider { return true; Matcher m = hidePattern.matcher(s); - if (strictMatching) { - if (m.matches()) { - return true; - } - } else if (m.find()) { + if (strictMatching ? m.matches() : m.find()) return true; - } } return false; } @@ -697,13 +688,8 @@ public class Options implements Cloneable, OptionProvider { public boolean matchesIncludeExpression(String s) { for (Pattern includePattern : includePatterns) { Matcher m = includePattern.matcher(s); - if (strictMatching) { - if (m.matches()) { - return true; - } - } else if (m.find()) { + if (strictMatching ? m.matches() : m.find()) return true; - } } return false; } @@ -716,13 +702,8 @@ public class Options implements Cloneable, OptionProvider { public boolean matchesCollPackageExpression(String s) { for (Pattern collPattern : collPackages) { Matcher m = collPattern.matcher(s); - if (strictMatching) { - if (m.matches()) { - return true; - } - } else if (m.find()) { + if (strictMatching ? m.matches() : m.find()) return true; - } } return false; } diff --git a/src/main/java/org/umlgraph/doclet/PackageMatcher.java b/src/main/java/org/umlgraph/doclet/PackageMatcher.java index c44c85e..99bd7ff 100644 --- a/src/main/java/org/umlgraph/doclet/PackageMatcher.java +++ b/src/main/java/org/umlgraph/doclet/PackageMatcher.java @@ -16,10 +16,9 @@ public class PackageMatcher implements ClassMatcher { } public boolean matches(String name) { - for (ClassDoc cd : packageDoc.allClasses()) { + for (ClassDoc cd : packageDoc.allClasses()) if (cd.qualifiedName().equals(name)) return true; - } return false; } diff --git a/src/main/java/org/umlgraph/doclet/PatternMatcher.java b/src/main/java/org/umlgraph/doclet/PatternMatcher.java index 84a1fb1..78a9135 100644 --- a/src/main/java/org/umlgraph/doclet/PatternMatcher.java +++ b/src/main/java/org/umlgraph/doclet/PatternMatcher.java @@ -16,7 +16,6 @@ */ package org.umlgraph.doclet; -import java.util.regex.Matcher; import java.util.regex.Pattern; import com.sun.javadoc.ClassDoc; @@ -38,8 +37,7 @@ public class PatternMatcher implements ClassMatcher { } public boolean matches(String name) { - Matcher matcher = pattern.matcher(name); - return matcher.matches(); + return pattern.matcher(name).matches(); } } diff --git a/src/main/java/org/umlgraph/doclet/RelationDirection.java b/src/main/java/org/umlgraph/doclet/RelationDirection.java index 2203f12..4d3595c 100644 --- a/src/main/java/org/umlgraph/doclet/RelationDirection.java +++ b/src/main/java/org/umlgraph/doclet/RelationDirection.java @@ -13,12 +13,9 @@ public enum RelationDirection { * @return */ public RelationDirection sum(RelationDirection d) { - if (this == NONE) - return d; - - if ((this == IN && d == OUT) || (this == OUT && d == IN) || this == BOTH || d == BOTH) - return BOTH; - return this; + // Handle same and nones first: + return (this == d || d == NONE) ? this : // + this == NONE ? d : BOTH; // They are different and not none. } /** @@ -28,10 +25,7 @@ public enum RelationDirection { * @return */ public boolean contains(RelationDirection d) { - if (this == BOTH) - return true; - else - return d == this; + return this == BOTH ? true : (d == this); } /** @@ -40,12 +34,7 @@ public enum RelationDirection { * @return */ public RelationDirection inverse() { - if (this == IN) - return OUT; - else if (this == OUT) - return IN; - else - return this; + return this == IN ? OUT : this == OUT ? IN : this; } }; diff --git a/src/main/java/org/umlgraph/doclet/Shape.java b/src/main/java/org/umlgraph/doclet/Shape.java index 1b457f2..e5db2eb 100644 --- a/src/main/java/org/umlgraph/doclet/Shape.java +++ b/src/main/java/org/umlgraph/doclet/Shape.java @@ -18,16 +18,6 @@ package org.umlgraph.doclet; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.ArrayList; -import java.util.List; - -import com.sun.javadoc.ClassDoc; -import com.sun.javadoc.Doc; -import com.sun.javadoc.LanguageVersion; -import com.sun.javadoc.RootDoc; - /** * Properties of node shapes * @@ -79,10 +69,7 @@ public class Shape { /** Return the shape's GraphViz landing port */ String landingPort() { - if (name.equals("class") || name.equals("activeclass")) - return ":p"; - else - return ""; + return (name.equals("class") || name.equals("activeclass")) ? ":p" : ""; } /** Return the table border required for the shape */ diff --git a/src/main/java/org/umlgraph/doclet/SubclassMatcher.java b/src/main/java/org/umlgraph/doclet/SubclassMatcher.java index 0588eda..999b823 100644 --- a/src/main/java/org/umlgraph/doclet/SubclassMatcher.java +++ b/src/main/java/org/umlgraph/doclet/SubclassMatcher.java @@ -25,17 +25,12 @@ public class SubclassMatcher implements ClassMatcher { return true; // recurse on supeclass, if available - if(cd.superclass() != null) - return matches(cd.superclass()); - - return false; + return cd.superclass() == null ? false : matches(cd.superclass()); } public boolean matches(String name) { ClassDoc cd = root.classNamed(name); - if(cd == null) - return false; - return matches(cd); + return cd == null ? false : matches(cd); } } diff --git a/src/main/java/org/umlgraph/doclet/UmlGraphDoc.java b/src/main/java/org/umlgraph/doclet/UmlGraphDoc.java index d61ab4a..fd04003 100644 --- a/src/main/java/org/umlgraph/doclet/UmlGraphDoc.java +++ b/src/main/java/org/umlgraph/doclet/UmlGraphDoc.java @@ -66,8 +66,7 @@ public class UmlGraphDoc { generatePackageDiagrams(root, opt, outputFolder); generateContextDiagrams(root, opt, outputFolder); } catch(Throwable t) { - root.printWarning("Error!"); - root.printWarning(t.toString()); + root.printWarning("Error: " + t.toString()); t.printStackTrace(); return false; } diff --git a/src/main/java/org/umlgraph/doclet/WrappedClassDoc.java b/src/main/java/org/umlgraph/doclet/WrappedClassDoc.java index 081e458..5478e4a 100644 --- a/src/main/java/org/umlgraph/doclet/WrappedClassDoc.java +++ b/src/main/java/org/umlgraph/doclet/WrappedClassDoc.java @@ -281,9 +281,7 @@ public class WrappedClassDoc implements ClassDoc { } public String name() { - if (name == null) - name = wrapped.name(); - return name; + return name != null ? name : (name = wrapped.name()); } public SourcePosition position() { @@ -331,9 +329,7 @@ public class WrappedClassDoc implements ClassDoc { } public Tag[] tags() { - if (tags == null) - tags = wrapped.tags(); - return tags; + return tags != null ? tags : (tags = wrapped.tags()); } public Tag[] tags(String arg0) { @@ -341,10 +337,7 @@ public class WrappedClassDoc implements ClassDoc { } public String toString() { - if (toString == null) { - toString = wrapped.toString(); - } - return toString; + return toString != null ? toString : (toString = wrapped.toString()); } public String typeName() {

"; - w.print(open + text + close + linePostfix); + private void tableLine(Align align, String text, Options opt, Font font) { + w.print("
" // + + fontWrap(" " + text + " ", opt, font) // + + "