mirror of https://github.com/dspinellis/UMLGraph
Introduced OptionProvider interface
This commit is contained in:
parent
405b179f20
commit
7d7a328406
|
|
@ -0,0 +1,11 @@
|
|||
package gr.spinellis.umlgraph.doclet;
|
||||
|
||||
import com.sun.javadoc.ClassDoc;
|
||||
|
||||
public interface OptionProvider {
|
||||
public Options getOptionsFor(ClassDoc cd);
|
||||
|
||||
public Options getOptionsFor(String name);
|
||||
|
||||
public Options getGlobalOptions();
|
||||
}
|
||||
|
|
@ -33,7 +33,7 @@ import java.util.regex.PatternSyntaxException;
|
|||
* @version $Revision$
|
||||
* @author <a href="http://www.spinellis.gr">Diomidis Spinellis</a>
|
||||
*/
|
||||
class Options implements Cloneable {
|
||||
class Options implements Cloneable, OptionProvider {
|
||||
private Vector<Pattern> hidePatterns;
|
||||
PrintWriter w;
|
||||
boolean showQualified;
|
||||
|
|
@ -335,5 +335,24 @@ class Options implements Cloneable {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* OptionProvider methods
|
||||
*/
|
||||
|
||||
public Options getOptionsFor(ClassDoc cd) {
|
||||
Options localOpt = (Options) this.clone();
|
||||
localOpt.setOptions(cd);
|
||||
return localOpt;
|
||||
}
|
||||
|
||||
public Options getOptionsFor(String name) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Options getGlobalOptions() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,82 +30,103 @@ import com.sun.javadoc.ClassDoc;
|
|||
import com.sun.javadoc.Tag;
|
||||
|
||||
/**
|
||||
* Contains the definition of a View. A View is a set of option overrides
|
||||
* that will lead to the creation of a UML class diagram. Multiple views can
|
||||
* be defined on the same source tree, effectively allowing to create multiple
|
||||
* Contains the definition of a View. A View is a set of option overrides that
|
||||
* will lead to the creation of a UML class diagram. Multiple views can be
|
||||
* defined on the same source tree, effectively allowing to create multiple
|
||||
* class diagram out of it.
|
||||
* @author wolf
|
||||
*
|
||||
*
|
||||
*/
|
||||
class View {
|
||||
class View implements OptionProvider {
|
||||
Map<Pattern, String[][]> optionOverrides = new LinkedHashMap<Pattern, String[][]>();
|
||||
ArrayList<String[]> globalOptions = new ArrayList<String[]>();
|
||||
ClassDoc viewDoc;
|
||||
|
||||
Options baseOptions;
|
||||
|
||||
/**
|
||||
* Builds a view given the class that contains its definition
|
||||
* @param c
|
||||
* @throws PatternSyntaxException
|
||||
*/
|
||||
public View(ClassDoc c) throws PatternSyntaxException {
|
||||
public View(ClassDoc c, Options generalOptions) throws PatternSyntaxException {
|
||||
this.viewDoc = c;
|
||||
this.baseOptions = (Options) generalOptions.clone();
|
||||
Tag[] tags = c.tags();
|
||||
String currPattern = null;
|
||||
// parse options, get the global ones, and build a map of the
|
||||
// pattern matched overrides
|
||||
List<String[]> patternOptions = new ArrayList<String[]>();
|
||||
List<String[]> globalOptions = new ArrayList<String[]>();
|
||||
for (int i = 0; i < tags.length; i++) {
|
||||
if(tags[i].name().equals("@match")) {
|
||||
if(currPattern != null) {
|
||||
String[][] options = patternOptions.toArray(new String[patternOptions.size()][]);
|
||||
if (tags[i].name().equals("@match")) {
|
||||
if (currPattern != null) {
|
||||
String[][] options = patternOptions
|
||||
.toArray(new String[patternOptions.size()][]);
|
||||
optionOverrides.put(Pattern.compile(currPattern), options);
|
||||
}
|
||||
currPattern = tags[i].text();
|
||||
} else if(tags[i].name().equals("@opt")) {
|
||||
patternOptions.clear();
|
||||
} else if (tags[i].name().equals("@opt")) {
|
||||
String[] opts = StringUtil.tokenize(tags[i].text());
|
||||
opts[0] = "-" + opts[0];
|
||||
if(currPattern == null) {
|
||||
if (currPattern == null) {
|
||||
globalOptions.add(opts);
|
||||
} else {
|
||||
patternOptions.add(opts);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(currPattern != null) {
|
||||
if (currPattern != null) {
|
||||
String[][] options = patternOptions.toArray(new String[patternOptions.size()][]);
|
||||
optionOverrides.put(Pattern.compile(currPattern), options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies global view overrides. <br>
|
||||
* If not output tag has been specified, the view name will be used as the output file name.
|
||||
*/
|
||||
public void applyOverrides(Options o) {
|
||||
|
||||
// apply the view global options
|
||||
boolean outputSet = false;
|
||||
for (String[] opts : globalOptions) {
|
||||
if(opts[0].equals("-output"))
|
||||
if (opts[0].equals("-output"))
|
||||
outputSet = true;
|
||||
o.setOption(opts);
|
||||
baseOptions.setOption(opts);
|
||||
}
|
||||
if(!outputSet)
|
||||
o.setOption(new String[] {"-output", viewDoc.name() + ".dot"});
|
||||
if (!outputSet)
|
||||
baseOptions.setOption(new String[] { "-output", viewDoc.name() + ".dot" });
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies local view overrides
|
||||
*/
|
||||
public void applyOverrides(Options o, ClassDoc c) {
|
||||
String className = c.toString();
|
||||
private void applyOverrides(Options o, String className) {
|
||||
for (Iterator<Map.Entry<Pattern, String[][]>> iter = optionOverrides.entrySet().iterator(); iter
|
||||
.hasNext();) {
|
||||
Map.Entry<Pattern, String[][]> mapEntry = iter.next();
|
||||
Pattern regex = mapEntry.getKey();
|
||||
Matcher matcher = regex.matcher(className);
|
||||
if (matcher.matches()) {
|
||||
String[][] overrides = mapEntry.getValue(); // the first element is in fact the pattern
|
||||
String[][] overrides = mapEntry.getValue();
|
||||
for (int i = 0; i < overrides.length; i++) {
|
||||
o.setOption(overrides[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// OptionProvider methods
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
public Options getOptionsFor(ClassDoc cd) {
|
||||
Options localOpt = (Options) baseOptions.clone();
|
||||
localOpt.setOptions(cd);
|
||||
applyOverrides(localOpt, cd.toString());
|
||||
return localOpt;
|
||||
}
|
||||
|
||||
public Options getOptionsFor(String name) {
|
||||
Options localOpt = (Options) baseOptions.clone();
|
||||
applyOverrides(localOpt, name);
|
||||
return localOpt;
|
||||
}
|
||||
|
||||
public Options getGlobalOptions() {
|
||||
return baseOptions;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
package gr.spinellis.umlgraph.doclet;
|
||||
|
||||
import com.sun.javadoc.ClassDoc;
|
||||
|
||||
public interface OptionProvider {
|
||||
public Options getOptionsFor(ClassDoc cd);
|
||||
|
||||
public Options getOptionsFor(String name);
|
||||
|
||||
public Options getGlobalOptions();
|
||||
}
|
||||
|
|
@ -33,7 +33,7 @@ import java.util.regex.PatternSyntaxException;
|
|||
* @version $Revision$
|
||||
* @author <a href="http://www.spinellis.gr">Diomidis Spinellis</a>
|
||||
*/
|
||||
class Options implements Cloneable {
|
||||
class Options implements Cloneable, OptionProvider {
|
||||
private Vector<Pattern> hidePatterns;
|
||||
PrintWriter w;
|
||||
boolean showQualified;
|
||||
|
|
@ -335,5 +335,24 @@ class Options implements Cloneable {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* OptionProvider methods
|
||||
*/
|
||||
|
||||
public Options getOptionsFor(ClassDoc cd) {
|
||||
Options localOpt = (Options) this.clone();
|
||||
localOpt.setOptions(cd);
|
||||
return localOpt;
|
||||
}
|
||||
|
||||
public Options getOptionsFor(String name) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Options getGlobalOptions() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,82 +30,103 @@ import com.sun.javadoc.ClassDoc;
|
|||
import com.sun.javadoc.Tag;
|
||||
|
||||
/**
|
||||
* Contains the definition of a View. A View is a set of option overrides
|
||||
* that will lead to the creation of a UML class diagram. Multiple views can
|
||||
* be defined on the same source tree, effectively allowing to create multiple
|
||||
* Contains the definition of a View. A View is a set of option overrides that
|
||||
* will lead to the creation of a UML class diagram. Multiple views can be
|
||||
* defined on the same source tree, effectively allowing to create multiple
|
||||
* class diagram out of it.
|
||||
* @author wolf
|
||||
*
|
||||
*
|
||||
*/
|
||||
class View {
|
||||
class View implements OptionProvider {
|
||||
Map<Pattern, String[][]> optionOverrides = new LinkedHashMap<Pattern, String[][]>();
|
||||
ArrayList<String[]> globalOptions = new ArrayList<String[]>();
|
||||
ClassDoc viewDoc;
|
||||
|
||||
Options baseOptions;
|
||||
|
||||
/**
|
||||
* Builds a view given the class that contains its definition
|
||||
* @param c
|
||||
* @throws PatternSyntaxException
|
||||
*/
|
||||
public View(ClassDoc c) throws PatternSyntaxException {
|
||||
public View(ClassDoc c, Options generalOptions) throws PatternSyntaxException {
|
||||
this.viewDoc = c;
|
||||
this.baseOptions = (Options) generalOptions.clone();
|
||||
Tag[] tags = c.tags();
|
||||
String currPattern = null;
|
||||
// parse options, get the global ones, and build a map of the
|
||||
// pattern matched overrides
|
||||
List<String[]> patternOptions = new ArrayList<String[]>();
|
||||
List<String[]> globalOptions = new ArrayList<String[]>();
|
||||
for (int i = 0; i < tags.length; i++) {
|
||||
if(tags[i].name().equals("@match")) {
|
||||
if(currPattern != null) {
|
||||
String[][] options = patternOptions.toArray(new String[patternOptions.size()][]);
|
||||
if (tags[i].name().equals("@match")) {
|
||||
if (currPattern != null) {
|
||||
String[][] options = patternOptions
|
||||
.toArray(new String[patternOptions.size()][]);
|
||||
optionOverrides.put(Pattern.compile(currPattern), options);
|
||||
}
|
||||
currPattern = tags[i].text();
|
||||
} else if(tags[i].name().equals("@opt")) {
|
||||
patternOptions.clear();
|
||||
} else if (tags[i].name().equals("@opt")) {
|
||||
String[] opts = StringUtil.tokenize(tags[i].text());
|
||||
opts[0] = "-" + opts[0];
|
||||
if(currPattern == null) {
|
||||
if (currPattern == null) {
|
||||
globalOptions.add(opts);
|
||||
} else {
|
||||
patternOptions.add(opts);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(currPattern != null) {
|
||||
if (currPattern != null) {
|
||||
String[][] options = patternOptions.toArray(new String[patternOptions.size()][]);
|
||||
optionOverrides.put(Pattern.compile(currPattern), options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies global view overrides. <br>
|
||||
* If not output tag has been specified, the view name will be used as the output file name.
|
||||
*/
|
||||
public void applyOverrides(Options o) {
|
||||
|
||||
// apply the view global options
|
||||
boolean outputSet = false;
|
||||
for (String[] opts : globalOptions) {
|
||||
if(opts[0].equals("-output"))
|
||||
if (opts[0].equals("-output"))
|
||||
outputSet = true;
|
||||
o.setOption(opts);
|
||||
baseOptions.setOption(opts);
|
||||
}
|
||||
if(!outputSet)
|
||||
o.setOption(new String[] {"-output", viewDoc.name() + ".dot"});
|
||||
if (!outputSet)
|
||||
baseOptions.setOption(new String[] { "-output", viewDoc.name() + ".dot" });
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies local view overrides
|
||||
*/
|
||||
public void applyOverrides(Options o, ClassDoc c) {
|
||||
String className = c.toString();
|
||||
private void applyOverrides(Options o, String className) {
|
||||
for (Iterator<Map.Entry<Pattern, String[][]>> iter = optionOverrides.entrySet().iterator(); iter
|
||||
.hasNext();) {
|
||||
Map.Entry<Pattern, String[][]> mapEntry = iter.next();
|
||||
Pattern regex = mapEntry.getKey();
|
||||
Matcher matcher = regex.matcher(className);
|
||||
if (matcher.matches()) {
|
||||
String[][] overrides = mapEntry.getValue(); // the first element is in fact the pattern
|
||||
String[][] overrides = mapEntry.getValue();
|
||||
for (int i = 0; i < overrides.length; i++) {
|
||||
o.setOption(overrides[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// OptionProvider methods
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
public Options getOptionsFor(ClassDoc cd) {
|
||||
Options localOpt = (Options) baseOptions.clone();
|
||||
localOpt.setOptions(cd);
|
||||
applyOverrides(localOpt, cd.toString());
|
||||
return localOpt;
|
||||
}
|
||||
|
||||
public Options getOptionsFor(String name) {
|
||||
Options localOpt = (Options) baseOptions.clone();
|
||||
applyOverrides(localOpt, name);
|
||||
return localOpt;
|
||||
}
|
||||
|
||||
public Options getGlobalOptions() {
|
||||
return baseOptions;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue