A few changes related to the needs of UMLDoc to generate relative links between diagrams in javadoc files, and a few that are needed for a separate project I'm working on: an "interactive" version of UMLGraph that allows the parsing of source files just once, and re-parses just the views when the user asks for, so that it's way faster to build the views by iterative changes on a big source code base (that code is in such a bad shape now that I don't feel like commiting it now)

This commit is contained in:
Andrea Aime 2006-06-02 09:03:32 +00:00
parent 6e7f99ef8c
commit a1f3f6ab6c
2 changed files with 46 additions and 20 deletions

View File

@ -43,13 +43,11 @@ import com.sun.javadoc.RootDoc;
public class UmlGraph {
/** Entry point */
public static boolean start(RootDoc root) throws IOException {
Options opt = new Options();
opt.setOptions(root.options());
opt.setOptions(findUMLOptions(root));
Options opt = buildOptions(root);
if (opt.verbose2)
System.out.println("UMLGraph doclet started");
View[] views = buildViews(opt, root);
View[] views = buildViews(opt, root, root);
if(views == null)
return false;
if (views.length == 0) {
@ -64,6 +62,17 @@ public class UmlGraph {
System.out.println("Class diagram generation complete");
return true;
}
/**
* Creates the base Options object, that contains both the options specified on the command
* line and the ones specified in the UMLOptions class, if available.
*/
public static Options buildOptions(RootDoc root) {
Options opt = new Options();
opt.setOptions(root.options());
opt.setOptions(findUMLOptions(root));
return opt;
}
private static ClassDoc findUMLOptions(RootDoc root) {
ClassDoc[] classes = root.classes();
@ -86,7 +95,7 @@ public class UmlGraph {
ClassGraph c = new ClassGraph(root, op, contextDoc);
c.prologue();
for (int i = 0; i < classes.length; i++) {
c.printClass(classes[i]);
c.printClass(classes[i], true);
}
for (int i = 0; i < classes.length; i++) {
c.printRelations(classes[i]);
@ -104,10 +113,14 @@ public class UmlGraph {
/**
* Builds the views according to the parameters on the command line
* @param opt The options
* @param srcRootDoc The RootDoc for the source classes
* @param viewRootDoc The RootDoc for the view classes (may be
* different, or may be the same as the srcRootDoc)
*/
private static View[] buildViews(Options opt, RootDoc root) {
public static View[] buildViews(Options opt, RootDoc srcRootDoc, RootDoc viewRootDoc) {
if (opt.viewName != null) {
ClassDoc viewClass = root.classNamed(opt.viewName);
ClassDoc viewClass = viewRootDoc.classNamed(opt.viewName);
if(viewClass == null) {
System.out.println("View " + opt.viewName + " not found! Exiting without generating any output.");
return null;
@ -120,15 +133,15 @@ public class UmlGraph {
System.out.println(viewClass + " is an abstract view, no output will be generated!");
return null;
}
return new View[] { buildView(root, viewClass, opt) };
return new View[] { buildView(srcRootDoc, viewClass, opt) };
} else if (opt.findViews) {
List<View> views = new ArrayList<View>();
ClassDoc[] classes = root.classes();
ClassDoc[] classes = viewRootDoc.classes();
// find view classes
for (int i = 0; i < classes.length; i++) {
if (classes[i].tags("view").length > 0 && !classes[i].isAbstract()) {
views.add(buildView(root, classes[i], opt));
views.add(buildView(srcRootDoc, classes[i], opt));
}
}

View File

@ -43,13 +43,11 @@ import com.sun.javadoc.RootDoc;
public class UmlGraph {
/** Entry point */
public static boolean start(RootDoc root) throws IOException {
Options opt = new Options();
opt.setOptions(root.options());
opt.setOptions(findUMLOptions(root));
Options opt = buildOptions(root);
if (opt.verbose2)
System.out.println("UMLGraph doclet started");
View[] views = buildViews(opt, root);
View[] views = buildViews(opt, root, root);
if(views == null)
return false;
if (views.length == 0) {
@ -64,6 +62,17 @@ public class UmlGraph {
System.out.println("Class diagram generation complete");
return true;
}
/**
* Creates the base Options object, that contains both the options specified on the command
* line and the ones specified in the UMLOptions class, if available.
*/
public static Options buildOptions(RootDoc root) {
Options opt = new Options();
opt.setOptions(root.options());
opt.setOptions(findUMLOptions(root));
return opt;
}
private static ClassDoc findUMLOptions(RootDoc root) {
ClassDoc[] classes = root.classes();
@ -86,7 +95,7 @@ public class UmlGraph {
ClassGraph c = new ClassGraph(root, op, contextDoc);
c.prologue();
for (int i = 0; i < classes.length; i++) {
c.printClass(classes[i]);
c.printClass(classes[i], true);
}
for (int i = 0; i < classes.length; i++) {
c.printRelations(classes[i]);
@ -104,10 +113,14 @@ public class UmlGraph {
/**
* Builds the views according to the parameters on the command line
* @param opt The options
* @param srcRootDoc The RootDoc for the source classes
* @param viewRootDoc The RootDoc for the view classes (may be
* different, or may be the same as the srcRootDoc)
*/
private static View[] buildViews(Options opt, RootDoc root) {
public static View[] buildViews(Options opt, RootDoc srcRootDoc, RootDoc viewRootDoc) {
if (opt.viewName != null) {
ClassDoc viewClass = root.classNamed(opt.viewName);
ClassDoc viewClass = viewRootDoc.classNamed(opt.viewName);
if(viewClass == null) {
System.out.println("View " + opt.viewName + " not found! Exiting without generating any output.");
return null;
@ -120,15 +133,15 @@ public class UmlGraph {
System.out.println(viewClass + " is an abstract view, no output will be generated!");
return null;
}
return new View[] { buildView(root, viewClass, opt) };
return new View[] { buildView(srcRootDoc, viewClass, opt) };
} else if (opt.findViews) {
List<View> views = new ArrayList<View>();
ClassDoc[] classes = root.classes();
ClassDoc[] classes = viewRootDoc.classes();
// find view classes
for (int i = 0; i < classes.length; i++) {
if (classes[i].tags("view").length > 0 && !classes[i].isAbstract()) {
views.add(buildView(root, classes[i], opt));
views.add(buildView(srcRootDoc, classes[i], opt));
}
}