-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathContextView.java
executable file
·119 lines (100 loc) · 3.71 KB
/
ContextView.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package org.umlgraph.doclet;
import java.io.IOException;
import java.util.regex.Pattern;
import com.sun.javadoc.ClassDoc;
import com.sun.javadoc.RootDoc;
/**
* A view designed for UMLDoc, filters out everything that it's not directly
* connected to the center class of the context.
* <p>
* As such, can be viewed as a simplified version of a {@linkplain View} using a
* single {@linkplain ContextMatcher}, but provides some extra configuration
* such as context highlighting and output path configuration (and it is
* specified in code rather than in javadoc comments).
* @author wolf
*
*/
public class ContextView implements OptionProvider {
private ClassDoc cd;
private ContextMatcher matcher;
private Options globalOptions;
private Options myGlobalOptions;
private Options hideOptions;
private Options centerOptions;
private Options packageOptions;
private static final String[] HIDE_OPTIONS = new String[] { "hide" };
public ContextView(String outputFolder, ClassDoc cd, RootDoc root, Options parent)
throws IOException {
this.cd = cd;
String outputPath = cd.containingPackage().name().replace('.', '/') + "/" + cd.name()
+ ".dot";
// setup options statically, so that we won't need to change them so
// often
this.globalOptions = parent.getGlobalOptions();
this.packageOptions = parent.getGlobalOptions();
this.packageOptions.showQualified = false;
this.myGlobalOptions = parent.getGlobalOptions();
this.myGlobalOptions.setOption(new String[] { "output", outputPath });
this.myGlobalOptions.setOption(HIDE_OPTIONS);
this.hideOptions = parent.getGlobalOptions();
this.hideOptions.setOption(HIDE_OPTIONS);
this.centerOptions = parent.getGlobalOptions();
this.centerOptions.nodeFillColor = "lemonChiffon";
this.centerOptions.showQualified = false;
this.matcher = new ContextMatcher(root, Pattern.compile(Pattern.quote(cd.toString())),
myGlobalOptions, true);
}
public void setContextCenter(ClassDoc contextCenter) {
this.cd = contextCenter;
String outputPath = cd.containingPackage().name().replace('.', '/') + "/" + cd.name()
+ ".dot";
this.myGlobalOptions.setOption(new String[] { "output", outputPath });
matcher.setContextCenter(Pattern.compile(Pattern.quote(cd.toString())));
}
public String getDisplayName() {
return "Context view for class " + cd;
}
public Options getGlobalOptions() {
return myGlobalOptions;
}
public Options getOptionsFor(ClassDoc cd) {
Options opt;
if (globalOptions.matchesHideExpression(cd.qualifiedName())
|| !(matcher.matches(cd) || globalOptions.matchesIncludeExpression(cd.qualifiedName()))) {
opt = hideOptions;
} else if (cd.equals(this.cd)) {
opt = centerOptions;
} else if(cd.containingPackage().equals(this.cd.containingPackage())){
opt = packageOptions;
} else {
opt = globalOptions;
}
Options optionClone = (Options) opt.clone();
overrideForClass(optionClone, cd);
return optionClone;
}
public Options getOptionsFor(String name) {
Options opt;
if (!matcher.matches(name))
opt = hideOptions;
else if (name.equals(cd.name()))
opt = centerOptions;
else
opt = globalOptions;
Options optionClone = (Options) opt.clone();
overrideForClass(optionClone, name);
return optionClone;
}
public void overrideForClass(Options opt, ClassDoc cd) {
opt.setOptions(cd);
if (opt.matchesHideExpression(cd.qualifiedName())
|| !(matcher.matches(cd) || opt.matchesIncludeExpression(cd.qualifiedName())))
opt.setOption(HIDE_OPTIONS);
if (cd.equals(this.cd))
opt.nodeFillColor = "lemonChiffon";
}
public void overrideForClass(Options opt, String className) {
if (!(matcher.matches(className) || opt.matchesIncludeExpression(className)))
opt.setOption(HIDE_OPTIONS);
}
}