From 3dc36ec4981f4a5b6cbc56a3086d0362f0f9aa2c Mon Sep 17 00:00:00 2001 From: Andrea Aime Date: Thu, 23 Feb 2006 19:49:27 +0000 Subject: [PATCH] Fixed a problematic situation. When all the operations of a class were hidden the generated html wasn't valid (see the test case, a class with a single hidden operation). Plus, when checking for hidden elements for elements other than a class, get the options against the containing class (the views are all based on class at the moment, we don't have views for methods or constructors) --- .../spinellis/umlgraph/doclet/ClassGraph.java | 39 ++++++++++++------- src/org/umlgraph/doclet/ClassGraph.java | 39 ++++++++++++------- 2 files changed, 50 insertions(+), 28 deletions(-) diff --git a/src/gr/spinellis/umlgraph/doclet/ClassGraph.java b/src/gr/spinellis/umlgraph/doclet/ClassGraph.java index 657f8d1..109d172 100644 --- a/src/gr/spinellis/umlgraph/doclet/ClassGraph.java +++ b/src/gr/spinellis/umlgraph/doclet/ClassGraph.java @@ -304,7 +304,8 @@ class ClassGraph { */ /** Print the class's constructors m */ - private void operations(Options opt, ConstructorDoc m[]) { + private boolean operations(Options opt, ConstructorDoc m[]) { + boolean printed = false; for (ConstructorDoc cd : m) { if (hidden(cd)) continue; @@ -316,26 +317,32 @@ class ClassGraph { cs += "()"; } tableLine(Align.LEFT, cs); + printed = true; tagvalue(opt, cd); } + return printed; } /** Print the class's operations m */ - private void operations(Options opt, MethodDoc m[]) { + private boolean operations(Options opt, MethodDoc m[]) { + boolean printed = false; for (MethodDoc md : m) { if (hidden(md)) continue; stereotype(opt, md, Align.LEFT); String op = visibility(opt, md) + md.name(); if (opt.showType) { - op += "(" + parameter(opt, md.parameters()) + ")" + typeAnnotation(opt, md.returnType()); + op += "(" + parameter(opt, md.parameters()) + ")" + + typeAnnotation(opt, md.returnType()); } else { op += "()"; } tableLine(Align.LEFT, op, opt, md.isAbstract() ? Font.ABSTRACT : Font.NORMAL); - + printed = true; + tagvalue(opt, md); } + return printed; } /** Print the common class node's properties */ @@ -384,14 +391,18 @@ class ClassGraph { } /** Return true if c has a @hidden tag associated with it */ - private boolean hidden(Doc c) { + 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 = optionProvider.getOptionsFor(c.toString()); + Options opt; + if(c instanceof ClassDoc) + opt = optionProvider.getOptionsFor(c.toString()); + else + opt = optionProvider.getOptionsFor(c.containingClass()); return opt.matchesHideExpression(c.toString()); } @@ -495,17 +506,17 @@ class ClassGraph { } if (!c.isEnum() && (opt.showConstructors || opt.showOperations)) { innerTableStart(); - if ((opt.showConstructors && c.constructors().length > 0) - || (opt.showOperations && c.methods().length > 0)) { - if (opt.showConstructors) - operations(opt, c.constructors()); - if (opt.showOperations) - operations(opt, c.methods()); - } else { + boolean printedLines = false; + if (opt.showConstructors) + printedLines |= operations(opt, c.constructors()); + if (opt.showOperations) + printedLines |= operations(opt, c.methods()); + + if (!printedLines) // if there are no operations nor constructors, // print an empty line to generate proper HTML tableLine(Align.LEFT, ""); - } + innerTableEnd(); } } diff --git a/src/org/umlgraph/doclet/ClassGraph.java b/src/org/umlgraph/doclet/ClassGraph.java index 657f8d1..109d172 100644 --- a/src/org/umlgraph/doclet/ClassGraph.java +++ b/src/org/umlgraph/doclet/ClassGraph.java @@ -304,7 +304,8 @@ class ClassGraph { */ /** Print the class's constructors m */ - private void operations(Options opt, ConstructorDoc m[]) { + private boolean operations(Options opt, ConstructorDoc m[]) { + boolean printed = false; for (ConstructorDoc cd : m) { if (hidden(cd)) continue; @@ -316,26 +317,32 @@ class ClassGraph { cs += "()"; } tableLine(Align.LEFT, cs); + printed = true; tagvalue(opt, cd); } + return printed; } /** Print the class's operations m */ - private void operations(Options opt, MethodDoc m[]) { + private boolean operations(Options opt, MethodDoc m[]) { + boolean printed = false; for (MethodDoc md : m) { if (hidden(md)) continue; stereotype(opt, md, Align.LEFT); String op = visibility(opt, md) + md.name(); if (opt.showType) { - op += "(" + parameter(opt, md.parameters()) + ")" + typeAnnotation(opt, md.returnType()); + op += "(" + parameter(opt, md.parameters()) + ")" + + typeAnnotation(opt, md.returnType()); } else { op += "()"; } tableLine(Align.LEFT, op, opt, md.isAbstract() ? Font.ABSTRACT : Font.NORMAL); - + printed = true; + tagvalue(opt, md); } + return printed; } /** Print the common class node's properties */ @@ -384,14 +391,18 @@ class ClassGraph { } /** Return true if c has a @hidden tag associated with it */ - private boolean hidden(Doc c) { + 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 = optionProvider.getOptionsFor(c.toString()); + Options opt; + if(c instanceof ClassDoc) + opt = optionProvider.getOptionsFor(c.toString()); + else + opt = optionProvider.getOptionsFor(c.containingClass()); return opt.matchesHideExpression(c.toString()); } @@ -495,17 +506,17 @@ class ClassGraph { } if (!c.isEnum() && (opt.showConstructors || opt.showOperations)) { innerTableStart(); - if ((opt.showConstructors && c.constructors().length > 0) - || (opt.showOperations && c.methods().length > 0)) { - if (opt.showConstructors) - operations(opt, c.constructors()); - if (opt.showOperations) - operations(opt, c.methods()); - } else { + boolean printedLines = false; + if (opt.showConstructors) + printedLines |= operations(opt, c.constructors()); + if (opt.showOperations) + printedLines |= operations(opt, c.methods()); + + if (!printedLines) // if there are no operations nor constructors, // print an empty line to generate proper HTML tableLine(Align.LEFT, ""); - } + innerTableEnd(); } }