mirror of https://github.com/dspinellis/UMLGraph
Merge pull request #62 from laurentschoelens/java9
jdk9 port of UMLGraph
This commit is contained in:
commit
6115e12837
|
|
@ -1,9 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src/main/java"/>
|
||||
<classpathentry kind="src" path="src/main/resources"/>
|
||||
<classpathentry kind="src" path="src/test/java"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="var" path="JDK_LIB/tools.jar"/>
|
||||
<classpathentry kind="output" path="build"/>
|
||||
</classpath>
|
||||
|
|
@ -3,7 +3,10 @@
|
|||
*.ipr
|
||||
*.iws
|
||||
*.swp
|
||||
.idea
|
||||
.settings
|
||||
.project
|
||||
.classpath
|
||||
_vimrc
|
||||
build
|
||||
CHECKSUM.MD5
|
||||
|
|
|
|||
17
.project
17
.project
|
|
@ -1,17 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>umlgraph_cvs</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
96
pom.xml
96
pom.xml
|
|
@ -6,7 +6,7 @@
|
|||
<artifactId>umlgraph</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>UMLGraph</name>
|
||||
<version>5.7.3-SNAPSHOT</version>
|
||||
<version>6.0.0-SNAPSHOT</version>
|
||||
<description>Declarative Drawing of UML Diagrams</description>
|
||||
<url>http://www.spinellis.gr/umlgraph</url>
|
||||
|
||||
|
|
@ -40,16 +40,15 @@
|
|||
<parent>
|
||||
<groupId>org.sonatype.oss</groupId>
|
||||
<artifactId>oss-parent</artifactId>
|
||||
<version>7</version>
|
||||
<version>9</version>
|
||||
</parent>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>sun.jdk</groupId>
|
||||
<artifactId>tools</artifactId>
|
||||
<version>1.5.0</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${java.home}/../lib/tools.jar</systemPath>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
|
@ -63,15 +62,16 @@
|
|||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<version>3.10.1</version>
|
||||
<configuration>
|
||||
<source>1.5</source>
|
||||
<target>1.5</target>
|
||||
<source>9</source>
|
||||
<target>9</target>
|
||||
</configuration>
|
||||
</plugin> <plugin>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.3.1</version>
|
||||
<version>3.3.0</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
|
|
@ -84,18 +84,18 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-release-plugin</artifactId>
|
||||
<version>2.5</version>
|
||||
<version>3.0.0-M7</version>
|
||||
<configuration>
|
||||
<autoVersionSubmodules>true</autoVersionSubmodules>
|
||||
<useReleaseProfile>false</useReleaseProfile>
|
||||
<releaseProfiles>release</releaseProfiles>
|
||||
<goals>deploy</goals>
|
||||
<autoVersionSubmodules>true</autoVersionSubmodules>
|
||||
<useReleaseProfile>false</useReleaseProfile>
|
||||
<releaseProfiles>release</releaseProfiles>
|
||||
<goals>deploy</goals>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>2.2.1</version>
|
||||
<version>3.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
|
|
@ -108,36 +108,40 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.9</version>
|
||||
<version>3.5.0</version>
|
||||
<configuration>
|
||||
<tags>
|
||||
<tag>
|
||||
<name>depend</name>
|
||||
<placement>X</placement>
|
||||
</tag>
|
||||
<tag>
|
||||
<name>hidden</name>
|
||||
<placement>X</placement>
|
||||
</tag>
|
||||
<tag>
|
||||
<name>opt</name>
|
||||
<placement>X</placement>
|
||||
</tag>
|
||||
</tags>
|
||||
<tags>
|
||||
<tag>
|
||||
<name>depend</name>
|
||||
<placement>X</placement>
|
||||
</tag>
|
||||
<tag>
|
||||
<name>hidden</name>
|
||||
<placement>X</placement>
|
||||
</tag>
|
||||
<tag>
|
||||
<name>opt</name>
|
||||
<placement>X</placement>
|
||||
</tag>
|
||||
</tags>
|
||||
<doclet>org.umlgraph.doclet.UmlGraphDoc</doclet>
|
||||
<docletPath>${project.build.directory}${file.separator}${project.build.finalName}.jar</docletPath>
|
||||
<additionalparam>-inferrel</additionalparam>
|
||||
<additionalparam>-inferdep</additionalparam>
|
||||
<additionalparam>-autosize</additionalparam>
|
||||
<additionalparam>-collapsible</additionalparam>
|
||||
<additionalparam>-hide java.*</additionalparam>
|
||||
<additionalparam>-collpackages</additionalparam>
|
||||
<additionalparam>-qualify</additionalparam>
|
||||
<additionalparam>-postfixpackage</additionalparam>
|
||||
<additionalparam>-nodefontsize 9</additionalparam>
|
||||
<additionalparam>-nodefontpackagesize 7</additionalparam>
|
||||
<additionalparam>-link http://docs.oracle.com/javase/7/docs/jdk/api/javadoc/doclet/</additionalparam>
|
||||
<additionalparam>-link http://download.oracle.com/javase/7/docs/api/</additionalparam>
|
||||
<additionalOptions>
|
||||
<option>-inferrel</option>
|
||||
<option>-inferdep</option>
|
||||
<option>-autosize</option>
|
||||
<option>-collapsible</option>
|
||||
<option>--hide="java.*"</option>
|
||||
<option>--collpackages=</option>
|
||||
<option>-qualify</option>
|
||||
<option>-all</option>
|
||||
<option>-postfixpackage</option>
|
||||
<option>-nodefontsize 9</option>
|
||||
<option>-nodefontpackagesize 7</option>
|
||||
<option>--link="https://docs.oracle.com/javase/7/docs/jdk/api/javadoc/doclet/"</option>
|
||||
<option>--link="https://download.oracle.com/javase/7/docs/api/"</option>
|
||||
</additionalOptions>
|
||||
<detectJavaApiLink>false</detectJavaApiLink>
|
||||
<useStandardDocletOptions>true</useStandardDocletOptions>
|
||||
</configuration>
|
||||
<executions>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
module org.umlgraph.doclet {
|
||||
exports org.umlgraph.doclet;
|
||||
opens org.umlgraph.doclet;
|
||||
|
||||
requires transitive jdk.javadoc;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -22,9 +22,12 @@ package org.umlgraph.doclet;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.lang.model.element.Name;
|
||||
|
||||
/**
|
||||
* Class's dot-compatible alias name (for fully qualified class names)
|
||||
* and printed information
|
||||
* Class's dot-compatible alias name (for fully qualified class names) and
|
||||
* printed information
|
||||
*
|
||||
* @version $Revision$
|
||||
* @author <a href="http://www.spinellis.gr">Diomidis Spinellis</a>
|
||||
*/
|
||||
|
|
@ -36,37 +39,35 @@ class ClassInfo {
|
|||
boolean nodePrinted;
|
||||
/** True if the class class node is hidden */
|
||||
boolean hidden;
|
||||
/**
|
||||
* The list of classes that share a relation with this one. Contains
|
||||
* all the classes linked with a bi-directional relation , and the ones
|
||||
* referred by a directed relation
|
||||
/**
|
||||
* The list of classes that share a relation with this one. Contains all the
|
||||
* classes linked with a bi-directional relation , and the ones referred by a
|
||||
* directed relation
|
||||
*/
|
||||
Map<String, RelationPattern> relatedClasses = new HashMap<String, RelationPattern>();
|
||||
Map<Name, RelationPattern> relatedClasses = new HashMap<>();
|
||||
|
||||
ClassInfo(boolean h) {
|
||||
hidden = h;
|
||||
name = "c" + classNumber;
|
||||
classNumber++;
|
||||
hidden = h;
|
||||
name = "c" + classNumber;
|
||||
classNumber++;
|
||||
}
|
||||
|
||||
public void addRelation(String dest, RelationType rt, RelationDirection d) {
|
||||
RelationPattern ri = relatedClasses.get(dest);
|
||||
if(ri == null) {
|
||||
ri = new RelationPattern(RelationDirection.NONE);
|
||||
relatedClasses.put(dest, ri);
|
||||
}
|
||||
ri.addRelation(rt, d);
|
||||
|
||||
public void addRelation(Name dest, RelationType rt, RelationDirection d) {
|
||||
RelationPattern ri = relatedClasses.get(dest);
|
||||
if (ri == null) {
|
||||
ri = new RelationPattern(RelationDirection.NONE);
|
||||
relatedClasses.put(dest, ri);
|
||||
}
|
||||
ri.addRelation(rt, d);
|
||||
}
|
||||
|
||||
public RelationPattern getRelation(String dest) {
|
||||
return relatedClasses.get(dest);
|
||||
|
||||
public RelationPattern getRelation(CharSequence dest) {
|
||||
return relatedClasses.get(dest);
|
||||
}
|
||||
|
||||
/** Start numbering from zero. */
|
||||
public static void reset() {
|
||||
classNumber = 0;
|
||||
classNumber = 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,22 +17,22 @@
|
|||
|
||||
package org.umlgraph.doclet;
|
||||
|
||||
import com.sun.javadoc.ClassDoc;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
|
||||
/**
|
||||
* A ClassMatcher is used to check if a class definition matches a
|
||||
* specific condition. The nature of the condition is dependent on
|
||||
* the kind of matcher
|
||||
* A ClassMatcher is used to check if a class definition matches a specific
|
||||
* condition. The nature of the condition is dependent on the kind of matcher
|
||||
*
|
||||
* @author wolf
|
||||
*/
|
||||
public interface ClassMatcher {
|
||||
/**
|
||||
* Returns the options for the specified class.
|
||||
* Returns the options for the specified class.
|
||||
*/
|
||||
public boolean matches(ClassDoc cd);
|
||||
|
||||
public boolean matches(TypeElement cd);
|
||||
|
||||
/**
|
||||
* Returns the options for the specified class.
|
||||
* Returns the options for the specified class.
|
||||
*/
|
||||
public boolean matches(String name);
|
||||
public boolean matches(CharSequence name);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,8 +26,10 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.sun.javadoc.ClassDoc;
|
||||
import com.sun.javadoc.RootDoc;
|
||||
import jdk.javadoc.doclet.DocletEnvironment;
|
||||
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
|
||||
/**
|
||||
* Matches classes that are directly connected to one of the classes matched by
|
||||
|
|
@ -38,6 +40,7 @@ import com.sun.javadoc.RootDoc;
|
|||
* This class needs to perform quite a bit of computations in order to gather
|
||||
* the network of class releationships, so you are allowed to reuse it should
|
||||
* you
|
||||
*
|
||||
* @author wolf
|
||||
*
|
||||
* @depend - - - DevNullWriter
|
||||
|
|
@ -45,34 +48,35 @@ import com.sun.javadoc.RootDoc;
|
|||
public class ContextMatcher implements ClassMatcher {
|
||||
ClassGraphHack cg;
|
||||
Pattern pattern;
|
||||
List<ClassDoc> matched;
|
||||
Set<String> visited = new HashSet<String>();
|
||||
List<TypeElement> matched;
|
||||
Set<String> visited = new HashSet<>();
|
||||
/** The options will be used to decide on inference */
|
||||
Options opt;
|
||||
RootDoc root;
|
||||
DocletEnvironment root;
|
||||
boolean keepParentHide;
|
||||
|
||||
/**
|
||||
* Builds the context matcher
|
||||
* @param root The root doc returned by JavaDoc
|
||||
* @param pattern The pattern that will match the "center" of this
|
||||
* context
|
||||
* @param keepParentHide If true, parent option hide patterns will be
|
||||
* preserved, so that classes hidden by the options won't
|
||||
* be shown in the context
|
||||
*
|
||||
* @param root The root doc returned by JavaDoc
|
||||
* @param pattern The pattern that will match the "center" of this
|
||||
* context
|
||||
* @param keepParentHide If true, parent option hide patterns will be preserved,
|
||||
* so that classes hidden by the options won't be shown in
|
||||
* the context
|
||||
* @throws IOException
|
||||
*/
|
||||
public ContextMatcher(RootDoc root, Pattern pattern, Options options, boolean keepParentHide) throws IOException {
|
||||
this.pattern = pattern;
|
||||
this.root = root;
|
||||
this.keepParentHide = keepParentHide;
|
||||
opt = (Options) options.clone();
|
||||
opt.setOption(new String[] { "!hide" });
|
||||
opt.setOption(new String[] { "!attributes" });
|
||||
opt.setOption(new String[] { "!operations" });
|
||||
this.cg = new ClassGraphHack(root, opt);
|
||||
public ContextMatcher(DocletEnvironment root, Pattern pattern, Options options, boolean keepParentHide) throws IOException {
|
||||
this.pattern = pattern;
|
||||
this.root = root;
|
||||
this.keepParentHide = keepParentHide;
|
||||
opt = (Options) options.clone();
|
||||
opt.setOption(new String[] { "!hide" });
|
||||
opt.setOption(new String[] { "!attributes" });
|
||||
opt.setOption(new String[] { "!operations" });
|
||||
this.cg = new ClassGraphHack(root, opt);
|
||||
|
||||
setContextCenter(pattern);
|
||||
setContextCenter(pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -80,116 +84,126 @@ public class ContextMatcher implements ClassMatcher {
|
|||
* <p>
|
||||
* This can be used to speed up subsequent matching with the same global
|
||||
* options, since the class network informations will be reused.
|
||||
*
|
||||
* @param pattern
|
||||
*/
|
||||
public void setContextCenter(Pattern pattern) {
|
||||
// build up the classgraph printing the relations for all of the
|
||||
// classes that make up the "center" of this context
|
||||
this.pattern = pattern;
|
||||
matched = new ArrayList<ClassDoc>();
|
||||
for (ClassDoc cd : root.classes()) {
|
||||
if (pattern.matcher(cd.toString()).matches()) {
|
||||
matched.add(cd);
|
||||
addToGraph(cd);
|
||||
}
|
||||
}
|
||||
// build up the classgraph printing the relations for all of the
|
||||
// classes that make up the "center" of this context
|
||||
this.pattern = pattern;
|
||||
matched = new ArrayList<>();
|
||||
for (Element cd : root.getIncludedElements()) {
|
||||
if (cd instanceof TypeElement && pattern.matcher(cd.toString()).matches()) {
|
||||
matched.add((TypeElement) cd);
|
||||
addToGraph((TypeElement) cd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the specified class to the internal class graph along with its
|
||||
* relations and dependencies, eventually inferring them, according to the
|
||||
* Options specified for this matcher
|
||||
* Adds the specified class to the internal class graph along with its relations
|
||||
* and dependencies, eventually inferring them, according to the Options
|
||||
* specified for this matcher
|
||||
*
|
||||
* @param cd
|
||||
*/
|
||||
private void addToGraph(ClassDoc cd) {
|
||||
// avoid adding twice the same class, but don't rely on cg.getClassInfo
|
||||
// since there are other ways to add a classInfor than printing the class
|
||||
if (visited.contains(cd.toString()))
|
||||
return;
|
||||
private void addToGraph(TypeElement cd) {
|
||||
// avoid adding twice the same class, but don't rely on cg.getClassInfo
|
||||
// since there are other ways to add a classInfor than printing the class
|
||||
if (visited.contains(cd.toString())) {
|
||||
return;
|
||||
}
|
||||
|
||||
visited.add(cd.toString());
|
||||
cg.printClass(cd, false);
|
||||
cg.printRelations(cd);
|
||||
if (opt.inferRelationships)
|
||||
cg.printInferredRelations(cd);
|
||||
if (opt.inferDependencies)
|
||||
cg.printInferredDependencies(cd);
|
||||
visited.add(cd.toString());
|
||||
cg.printClass(cd, false);
|
||||
cg.printRelations(cd);
|
||||
if (opt.inferRelationships) {
|
||||
cg.printInferredRelations(cd);
|
||||
}
|
||||
if (opt.inferDependencies) {
|
||||
cg.printInferredDependencies(cd);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.umlgraph.doclet.ClassMatcher#matches(com.sun.javadoc.ClassDoc)
|
||||
* @see org.umlgraph.doclet.ClassMatcher#matches(TypeElement)
|
||||
*/
|
||||
public boolean matches(ClassDoc cd) {
|
||||
if (keepParentHide && opt.matchesHideExpression(cd.toString()))
|
||||
return false;
|
||||
public boolean matches(TypeElement cd) {
|
||||
if (keepParentHide && opt.matchesHideExpression(cd.getQualifiedName())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// if the class is matched, it's in by default.
|
||||
if (matched.contains(cd))
|
||||
return true;
|
||||
// if the class is matched, it's in by default.
|
||||
if (matched.contains(cd)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// otherwise, add the class to the graph and see if it's associated
|
||||
// with any of the matched classes using the classgraph hack
|
||||
addToGraph(cd);
|
||||
return matches(cd.toString());
|
||||
// otherwise, add the class to the graph and see if it's associated
|
||||
// with any of the matched classes using the classgraph hack
|
||||
addToGraph(cd);
|
||||
return matches(cd.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.umlgraph.doclet.ClassMatcher#matches(java.lang.String)
|
||||
* @see org.umlgraph.doclet.ClassMatcher#matches(CharSequence)
|
||||
*/
|
||||
public boolean matches(String name) {
|
||||
if (pattern.matcher(name).matches())
|
||||
return true;
|
||||
public boolean matches(CharSequence name) {
|
||||
if (pattern.matcher(name).matches()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (ClassDoc mcd : matched) {
|
||||
RelationPattern rp = cg.getClassInfo(mcd, true).getRelation(name);
|
||||
if (rp != null && opt.contextRelationPattern.matchesOne(rp))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
for (TypeElement mcd : matched) {
|
||||
RelationPattern rp = cg.getClassInfo(mcd, true).getRelation(name);
|
||||
if (rp != null && opt.contextRelationPattern.matchesOne(rp)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* A quick hack to compute class dependencies reusing ClassGraph but
|
||||
* without generating output. Will be removed once the ClassGraph class
|
||||
* will be split into two classes for graph computation and output
|
||||
* generation.
|
||||
* A quick hack to compute class dependencies reusing ClassGraph but without
|
||||
* generating output. Will be removed once the ClassGraph class will be split
|
||||
* into two classes for graph computation and output generation.
|
||||
*
|
||||
* @author wolf
|
||||
*
|
||||
*/
|
||||
private static class ClassGraphHack extends ClassGraph {
|
||||
|
||||
public ClassGraphHack(RootDoc root, OptionProvider optionProvider) throws IOException {
|
||||
super(root, optionProvider, null);
|
||||
prologue();
|
||||
}
|
||||
public ClassGraphHack(DocletEnvironment root, OptionProvider optionProvider) throws IOException {
|
||||
super(root, optionProvider, null);
|
||||
prologue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prologue() throws IOException {
|
||||
w = new PrintWriter(new DevNullWriter());
|
||||
}
|
||||
@Override
|
||||
public void prologue() throws IOException {
|
||||
w = new PrintWriter(new DevNullWriter());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple dev/null imitation
|
||||
*
|
||||
* @author wolf
|
||||
*/
|
||||
private static class DevNullWriter extends Writer {
|
||||
|
||||
@Override
|
||||
public void write(char[] cbuf, int off, int len) throws IOException {
|
||||
// nothing to do
|
||||
}
|
||||
@Override
|
||||
public void write(char[] cbuf, int off, int len) throws IOException {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() throws IOException {
|
||||
// nothing to do
|
||||
}
|
||||
@Override
|
||||
public void flush() throws IOException {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
// nothing to do
|
||||
}
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,14 @@ package org.umlgraph.doclet;
|
|||
import java.io.IOException;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.sun.javadoc.ClassDoc;
|
||||
import com.sun.javadoc.RootDoc;
|
||||
import jdk.javadoc.doclet.DocletEnvironment;
|
||||
|
||||
import javax.lang.model.element.ModuleElement;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
|
||||
import org.umlgraph.doclet.util.ElementUtil;
|
||||
|
||||
import com.sun.source.util.DocTrees;
|
||||
|
||||
/**
|
||||
* A view designed for UMLDoc, filters out everything that it's not directly
|
||||
|
|
@ -14,12 +20,14 @@ import com.sun.javadoc.RootDoc;
|
|||
* 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 TypeElement cd;
|
||||
private DocletEnvironment root;
|
||||
private ContextMatcher matcher;
|
||||
private Options globalOptions;
|
||||
private Options myGlobalOptions;
|
||||
|
|
@ -28,93 +36,98 @@ public class ContextView implements OptionProvider {
|
|||
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";
|
||||
public ContextView(String outputFolder, TypeElement cd, DocletEnvironment root, Options parent) throws IOException {
|
||||
this.cd = cd;
|
||||
this.root = root;
|
||||
ModuleElement md = ElementUtil.getModuleOf(root, cd);
|
||||
String pathPrefix = Runtime.version().major() > 10 && md != null ? md.getQualifiedName().toString() + "/" : "";
|
||||
String outputPath = pathPrefix + ElementUtil.getPackageOf(root, cd).getQualifiedName().toString().replace('.', '/') + "/" + cd.getSimpleName() + ".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;
|
||||
// setup options statically, so that we won't need to change them so
|
||||
// often
|
||||
this.globalOptions = parent.getGlobalOptions();
|
||||
|
||||
this.myGlobalOptions = parent.getGlobalOptions();
|
||||
this.myGlobalOptions.setOption(new String[] { "output", outputPath });
|
||||
this.myGlobalOptions.setOption(HIDE_OPTIONS);
|
||||
this.packageOptions = parent.getGlobalOptions();
|
||||
this.packageOptions.showQualified = false;
|
||||
|
||||
this.hideOptions = parent.getGlobalOptions();
|
||||
this.hideOptions.setOption(HIDE_OPTIONS);
|
||||
this.myGlobalOptions = parent.getGlobalOptions();
|
||||
this.myGlobalOptions.setOption(new String[] { "output", outputPath });
|
||||
this.myGlobalOptions.setOption(HIDE_OPTIONS);
|
||||
|
||||
this.centerOptions = parent.getGlobalOptions();
|
||||
this.centerOptions.nodeFillColor = "lemonChiffon";
|
||||
this.centerOptions.showQualified = false;
|
||||
this.hideOptions = parent.getGlobalOptions();
|
||||
this.hideOptions.setOption(HIDE_OPTIONS);
|
||||
|
||||
this.matcher = new ContextMatcher(root, Pattern.compile(Pattern.quote(cd.toString())),
|
||||
myGlobalOptions, true);
|
||||
this.centerOptions = parent.getGlobalOptions();
|
||||
this.centerOptions.nodeFillColor = "lemonChiffon";
|
||||
this.centerOptions.showQualified = false;
|
||||
|
||||
this.matcher = new ContextMatcher(root, Pattern.compile(Pattern.quote(cd.getQualifiedName().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 void setContextCenter(TypeElement contextCenter) {
|
||||
this.cd = contextCenter;
|
||||
ModuleElement md = ElementUtil.getModuleOf(root, contextCenter);
|
||||
String pathPrefix = Runtime.version().major() > 10 && md != null ? md.getQualifiedName().toString() + "/" : "";
|
||||
String outputPath = pathPrefix + ElementUtil.getPackageOf(root, cd).getQualifiedName().toString().replace('.', '/') + "/" + cd.getSimpleName() + ".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;
|
||||
return "Context view for class " + cd;
|
||||
}
|
||||
|
||||
public Options getGlobalOptions() {
|
||||
return myGlobalOptions;
|
||||
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(DocTrees dt, TypeElement cd) {
|
||||
Options opt;
|
||||
if (globalOptions.matchesHideExpression(cd.getQualifiedName())
|
||||
|| !(matcher.matches(cd) || globalOptions.matchesIncludeExpression(cd.getQualifiedName()))) {
|
||||
opt = hideOptions;
|
||||
} else if (cd.equals(this.cd)) {
|
||||
opt = centerOptions;
|
||||
} else if (root.getElementUtils().getPackageOf(cd).equals(root.getElementUtils().getPackageOf(this.cd))) {
|
||||
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 Options getOptionsFor(CharSequence name) {
|
||||
Options opt;
|
||||
if (!matcher.matches(name)) {
|
||||
opt = hideOptions;
|
||||
} else if (name.equals(cd.getQualifiedName())) {
|
||||
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, TypeElement cd) {
|
||||
opt.setOptions(root.getDocTrees(), cd);
|
||||
if (opt.matchesHideExpression(cd.getQualifiedName())
|
||||
|| !(matcher.matches(cd) || opt.matchesIncludeExpression(cd.getQualifiedName()))) {
|
||||
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);
|
||||
public void overrideForClass(Options opt, CharSequence className) {
|
||||
if (!(matcher.matches(className) || opt.matchesIncludeExpression(className))) {
|
||||
opt.setOption(HIDE_OPTIONS);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ package org.umlgraph.doclet;
|
|||
* Class to represent a font for graphviz.
|
||||
* <p>
|
||||
* This is a fairly complicated model, because it is rather an API into graphviz
|
||||
* formatting strings rather than a standalone thing. <p Some fonts (edge, node,
|
||||
* formatting strings rather than a standalone thing. <p> Some fonts (edge, node,
|
||||
* abstract) are set on the top level elements, whereas others (class name, tag,
|
||||
* package) are inserted as {@code <font>} tags, and these can be omitted if not
|
||||
* set. Inheritance of properties then happens in graphviz.
|
||||
|
|
@ -33,12 +33,12 @@ public enum Font {
|
|||
|
||||
// Static initialization of further values.
|
||||
static {
|
||||
// use an appropriate font depending on the current operating system
|
||||
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
|
||||
DEFAULT_FONT = "Arial";
|
||||
} else {
|
||||
DEFAULT_FONT = "Helvetica"; // TODO: can we use just "sans"?
|
||||
}
|
||||
// use an appropriate font depending on the current operating system
|
||||
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
|
||||
DEFAULT_FONT = "Arial";
|
||||
} else {
|
||||
DEFAULT_FONT = "Helvetica"; // TODO: can we use just "sans"?
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -49,53 +49,53 @@ public enum Font {
|
|||
* @return Wrapped text
|
||||
*/
|
||||
public String wrap(Options opt, String text) {
|
||||
if (text.isEmpty() || this == NORMAL)
|
||||
return text;
|
||||
String face = null;
|
||||
double size = -1;
|
||||
boolean italic = false;
|
||||
switch (this) {
|
||||
case EDGE:
|
||||
case NODE:
|
||||
// Not used with the wrap function.
|
||||
throw new UnsupportedOperationException();
|
||||
case ABSTRACT:
|
||||
italic = opt.nodeFontAbstractItalic;
|
||||
case NORMAL:
|
||||
break;
|
||||
case CLASS_ABSTRACT:
|
||||
italic = opt.nodeFontAbstractItalic;
|
||||
case CLASS:
|
||||
face = opt.nodeFontClassName;
|
||||
size = opt.nodeFontClassSize;
|
||||
break;
|
||||
case PACKAGE:
|
||||
face = opt.nodeFontPackageName;
|
||||
size = opt.nodeFontPackageSize;
|
||||
break;
|
||||
case TAG:
|
||||
face = opt.nodeFontTagName;
|
||||
size = opt.nodeFontTagSize;
|
||||
break;
|
||||
}
|
||||
if (face == null && size < 0 && !italic)
|
||||
return text;
|
||||
StringBuilder buf = new StringBuilder(text.length() + 100);
|
||||
if (face != null || size > 0) {
|
||||
buf.append("<font");
|
||||
if (face != null)
|
||||
buf.append(" face=\"").append(face).append('"');
|
||||
if (size > 0)
|
||||
buf.append(" point-size=\"").append(size).append('"');
|
||||
buf.append('>');
|
||||
}
|
||||
if (italic)
|
||||
buf.append("<i>");
|
||||
buf.append(text);
|
||||
if (italic)
|
||||
buf.append("</i>");
|
||||
if (face != null || size > 0)
|
||||
buf.append("</font>");
|
||||
return buf.toString();
|
||||
if (text.isEmpty() || this == NORMAL)
|
||||
return text;
|
||||
String face = null;
|
||||
double size = -1;
|
||||
boolean italic = false;
|
||||
switch (this) {
|
||||
case EDGE:
|
||||
case NODE:
|
||||
// Not used with the wrap function.
|
||||
throw new UnsupportedOperationException();
|
||||
case ABSTRACT:
|
||||
italic = opt.nodeFontAbstractItalic;
|
||||
case NORMAL:
|
||||
break;
|
||||
case CLASS_ABSTRACT:
|
||||
italic = opt.nodeFontAbstractItalic;
|
||||
case CLASS:
|
||||
face = opt.nodeFontClassName;
|
||||
size = opt.nodeFontClassSize;
|
||||
break;
|
||||
case PACKAGE:
|
||||
face = opt.nodeFontPackageName;
|
||||
size = opt.nodeFontPackageSize;
|
||||
break;
|
||||
case TAG:
|
||||
face = opt.nodeFontTagName;
|
||||
size = opt.nodeFontTagSize;
|
||||
break;
|
||||
}
|
||||
if (face == null && size < 0 && !italic)
|
||||
return text;
|
||||
StringBuilder buf = new StringBuilder(text.length() + 100);
|
||||
if (face != null || size > 0) {
|
||||
buf.append("<font");
|
||||
if (face != null)
|
||||
buf.append(" face=\"").append(face).append('"');
|
||||
if (size > 0)
|
||||
buf.append(" point-size=\"").append(size).append('"');
|
||||
buf.append('>');
|
||||
}
|
||||
if (italic)
|
||||
buf.append("<i>");
|
||||
buf.append(text);
|
||||
if (italic)
|
||||
buf.append("</i>");
|
||||
if (face != null || size > 0)
|
||||
buf.append("</font>");
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,41 +2,51 @@ package org.umlgraph.doclet;
|
|||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.sun.javadoc.ClassDoc;
|
||||
import com.sun.javadoc.RootDoc;
|
||||
import jdk.javadoc.doclet.DocletEnvironment;
|
||||
|
||||
import javax.lang.model.element.ElementKind;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
|
||||
import org.umlgraph.doclet.util.ElementUtil;
|
||||
|
||||
/**
|
||||
* Matches every class that implements (directly or indirectly) an
|
||||
* interfaces matched by regular expression provided.
|
||||
* Matches every class that implements (directly or indirectly) an interfaces
|
||||
* matched by regular expression provided.
|
||||
*/
|
||||
public class InterfaceMatcher implements ClassMatcher {
|
||||
|
||||
protected RootDoc root;
|
||||
protected DocletEnvironment root;
|
||||
protected Pattern pattern;
|
||||
|
||||
public InterfaceMatcher(RootDoc root, Pattern pattern) {
|
||||
this.root = root;
|
||||
this.pattern = pattern;
|
||||
public InterfaceMatcher(DocletEnvironment root, Pattern pattern) {
|
||||
this.root = root;
|
||||
this.pattern = pattern;
|
||||
}
|
||||
|
||||
public boolean matches(ClassDoc cd) {
|
||||
// if it's the interface we're looking for, match
|
||||
if(cd.isInterface() && pattern.matcher(cd.toString()).matches())
|
||||
return true;
|
||||
|
||||
// for each interface, recurse, since classes and interfaces
|
||||
// are treated the same in the doclet API
|
||||
for (ClassDoc iface : cd.interfaces())
|
||||
if(matches(iface))
|
||||
return true;
|
||||
|
||||
// recurse on supeclass, if available
|
||||
return cd.superclass() == null ? false : matches(cd.superclass());
|
||||
public boolean matches(TypeElement cd) {
|
||||
// if it's the interface we're looking for, match
|
||||
if (cd.getKind() == ElementKind.INTERFACE && pattern.matcher(cd.toString()).matches()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// for each interface, recurse, since classes and interfaces
|
||||
// are treated the same in the doclet API
|
||||
for (TypeMirror type : cd.getInterfaces()) {
|
||||
TypeElement iType = ElementUtil.getTypeElement(type);
|
||||
if (iType != null && matches(iType)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// recurse on superclass, if available
|
||||
TypeElement scd = ElementUtil.getTypeElement(cd.getSuperclass());
|
||||
return scd == null ? false : matches(scd);
|
||||
}
|
||||
|
||||
public boolean matches(String name) {
|
||||
ClassDoc cd = root.classNamed(name);
|
||||
return cd == null ? false : matches(cd);
|
||||
public boolean matches(CharSequence name) {
|
||||
TypeElement cd = root.getElementUtils().getTypeElement(name);
|
||||
return cd == null ? false : matches(cd);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,53 @@
|
|||
package org.umlgraph.doclet;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import jdk.javadoc.doclet.Doclet;
|
||||
|
||||
/**
|
||||
* A base class for declaring options. Subtypes for specific options should
|
||||
* implement the {@link #process(String,List) process} method to handle
|
||||
* instances of the option found on the command line.
|
||||
*/
|
||||
public abstract class Option implements Doclet.Option {
|
||||
private final String name;
|
||||
private final int argumentCount;
|
||||
private final String description;
|
||||
private final String parameters;
|
||||
|
||||
public Option(String name, boolean hasArg, String description, String parameters) {
|
||||
this(name, hasArg ? 1 : 0, description, parameters);
|
||||
}
|
||||
|
||||
public Option(String name, int argumentCount, String description, String parameters) {
|
||||
this.name = name;
|
||||
this.argumentCount = argumentCount;
|
||||
this.description = description;
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getArgumentCount() {
|
||||
return argumentCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.STANDARD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNames() {
|
||||
return List.of(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParameters() {
|
||||
return argumentCount == 0 ? "" : parameters;
|
||||
}
|
||||
}
|
||||
|
|
@ -17,22 +17,23 @@
|
|||
|
||||
package org.umlgraph.doclet;
|
||||
|
||||
import com.sun.javadoc.ClassDoc;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
|
||||
import com.sun.source.util.DocTrees;
|
||||
|
||||
/**
|
||||
* A factory class that builds Options object for general use or for a
|
||||
* specific class
|
||||
* A factory class that builds Options object for general use or for a specific class
|
||||
*/
|
||||
public interface OptionProvider {
|
||||
/**
|
||||
* Returns the options for the specified class.
|
||||
*/
|
||||
public Options getOptionsFor(ClassDoc cd);
|
||||
public Options getOptionsFor(DocTrees dt, TypeElement cd);
|
||||
|
||||
/**
|
||||
* Returns the options for the specified class.
|
||||
*/
|
||||
public Options getOptionsFor(String name);
|
||||
public Options getOptionsFor(CharSequence name);
|
||||
|
||||
/**
|
||||
* Returns the global options (the class independent definition)
|
||||
|
|
@ -42,16 +43,17 @@ public interface OptionProvider {
|
|||
/**
|
||||
* Gets a base Options and applies the overrides for the specified class
|
||||
*/
|
||||
public void overrideForClass(Options opt, ClassDoc cd);
|
||||
public void overrideForClass(Options opt, TypeElement cd);
|
||||
|
||||
/**
|
||||
* Gets a base Options and applies the overrides for the specified class
|
||||
*/
|
||||
public void overrideForClass(Options opt, String className);
|
||||
public void overrideForClass(Options opt, CharSequence className);
|
||||
|
||||
/**
|
||||
* Returns user displayable name for this option provider.
|
||||
* <p>Will be used to provide progress feedback on the console
|
||||
* <p>
|
||||
* Will be used to provide progress feedback on the console
|
||||
*/
|
||||
public String getDisplayName();
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,25 +1,33 @@
|
|||
package org.umlgraph.doclet;
|
||||
|
||||
import com.sun.javadoc.ClassDoc;
|
||||
import com.sun.javadoc.PackageDoc;
|
||||
import jdk.javadoc.doclet.DocletEnvironment;
|
||||
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.PackageElement;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
|
||||
import org.umlgraph.doclet.util.ElementUtil;
|
||||
|
||||
public class PackageMatcher implements ClassMatcher {
|
||||
protected PackageDoc packageDoc;
|
||||
protected DocletEnvironment root;
|
||||
protected PackageElement packageDoc;
|
||||
|
||||
public PackageMatcher(PackageDoc packageDoc) {
|
||||
super();
|
||||
this.packageDoc = packageDoc;
|
||||
public PackageMatcher(DocletEnvironment root, PackageElement packageDoc) {
|
||||
this.root = root;
|
||||
this.packageDoc = packageDoc;
|
||||
}
|
||||
|
||||
public boolean matches(ClassDoc cd) {
|
||||
return cd.containingPackage().equals(packageDoc);
|
||||
public boolean matches(TypeElement cd) {
|
||||
return packageDoc.equals(ElementUtil.getPackageOf(root, cd));
|
||||
}
|
||||
|
||||
public boolean matches(String name) {
|
||||
for (ClassDoc cd : packageDoc.allClasses())
|
||||
if (cd.qualifiedName().equals(name))
|
||||
return true;
|
||||
return false;
|
||||
public boolean matches(CharSequence name) {
|
||||
for (Element cd : packageDoc.getEnclosedElements()) {
|
||||
if (cd instanceof TypeElement && ((TypeElement) cd).getQualifiedName().equals(name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,14 @@
|
|||
package org.umlgraph.doclet;
|
||||
|
||||
import com.sun.javadoc.ClassDoc;
|
||||
import com.sun.javadoc.PackageDoc;
|
||||
import com.sun.javadoc.RootDoc;
|
||||
import jdk.javadoc.doclet.DocletEnvironment;
|
||||
|
||||
import javax.lang.model.element.ModuleElement;
|
||||
import javax.lang.model.element.PackageElement;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
|
||||
import org.umlgraph.doclet.util.ElementUtil;
|
||||
|
||||
import com.sun.source.util.DocTrees;
|
||||
|
||||
/**
|
||||
* A view designed for UMLDoc, filters out everything that it's not contained in
|
||||
|
|
@ -12,70 +18,78 @@ import com.sun.javadoc.RootDoc;
|
|||
* single {@linkplain ClassMatcher}, and provides some extra configuration such
|
||||
* as output path configuration (and it is specified in code rather than in
|
||||
* javadoc comments).
|
||||
*
|
||||
* @author wolf
|
||||
*
|
||||
*/
|
||||
public class PackageView implements OptionProvider {
|
||||
|
||||
private static final String[] HIDE = new String[] { "hide" };
|
||||
private PackageDoc pd;
|
||||
private PackageElement pd;
|
||||
private OptionProvider parent;
|
||||
private ClassMatcher matcher;
|
||||
private String outputPath;
|
||||
private Options opt;
|
||||
private DocTrees docTrees;
|
||||
|
||||
public PackageView(String outputFolder, PackageDoc pd, RootDoc root, OptionProvider parent) {
|
||||
this.parent = parent;
|
||||
this.pd = pd;
|
||||
this.matcher = new PackageMatcher(pd);
|
||||
this.opt = parent.getGlobalOptions();
|
||||
this.opt.setOptions(pd);
|
||||
this.outputPath = pd.name().replace('.', '/') + "/" + pd.name() + ".dot";
|
||||
public PackageView(String outputFolder, PackageElement pd, DocletEnvironment root, OptionProvider parent) {
|
||||
this.parent = parent;
|
||||
this.pd = pd;
|
||||
this.docTrees = root.getDocTrees();
|
||||
this.matcher = new PackageMatcher(root, pd);
|
||||
this.opt = parent.getGlobalOptions();
|
||||
this.opt.setOptions(docTrees, pd);
|
||||
ModuleElement md = ElementUtil.getModuleOf(root, pd);
|
||||
String pathPrefix = Runtime.version().major() > 10 && md != null ? md.getQualifiedName().toString() + "/" : "";
|
||||
this.outputPath = pathPrefix + pd.getQualifiedName().toString().replace('.', '/') + "/" + pd.getSimpleName().toString() + ".dot";
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return "Package view for package " + pd;
|
||||
return "Package view for package " + pd;
|
||||
}
|
||||
|
||||
public Options getGlobalOptions() {
|
||||
Options go = parent.getGlobalOptions();
|
||||
Options go = parent.getGlobalOptions();
|
||||
|
||||
go.setOption(new String[] { "output", outputPath });
|
||||
go.setOption(HIDE);
|
||||
go.setOption(new String[] { "output", outputPath });
|
||||
go.setOption(HIDE);
|
||||
|
||||
return go;
|
||||
return go;
|
||||
}
|
||||
|
||||
public Options getOptionsFor(ClassDoc cd) {
|
||||
Options go = parent.getGlobalOptions();
|
||||
overrideForClass(go, cd);
|
||||
return go;
|
||||
public Options getOptionsFor(DocTrees dt, TypeElement cd) {
|
||||
Options go = parent.getGlobalOptions();
|
||||
overrideForClass(go, cd);
|
||||
return go;
|
||||
}
|
||||
|
||||
public Options getOptionsFor(String name) {
|
||||
Options go = parent.getGlobalOptions();
|
||||
overrideForClass(go, name);
|
||||
return go;
|
||||
public Options getOptionsFor(CharSequence name) {
|
||||
Options go = parent.getGlobalOptions();
|
||||
overrideForClass(go, name);
|
||||
return go;
|
||||
}
|
||||
|
||||
public void overrideForClass(Options opt, ClassDoc cd) {
|
||||
opt.setOptions(cd);
|
||||
boolean inPackage = matcher.matches(cd);
|
||||
if (inPackage)
|
||||
opt.showQualified = false;
|
||||
boolean included = inPackage || this.opt.matchesIncludeExpression(cd.qualifiedName());
|
||||
if (!included || this.opt.matchesHideExpression(cd.qualifiedName()))
|
||||
opt.setOption(HIDE);
|
||||
public void overrideForClass(Options opt, TypeElement cd) {
|
||||
opt.setOptions(docTrees, cd);
|
||||
boolean inPackage = matcher.matches(cd);
|
||||
if (inPackage) {
|
||||
opt.showQualified = false;
|
||||
}
|
||||
boolean included = inPackage || this.opt.matchesIncludeExpression(cd.getQualifiedName());
|
||||
if (!included || this.opt.matchesHideExpression(cd.getQualifiedName())) {
|
||||
opt.setOption(HIDE);
|
||||
}
|
||||
}
|
||||
|
||||
public void overrideForClass(Options opt, String className) {
|
||||
opt.showQualified = false;
|
||||
boolean inPackage = matcher.matches(className);
|
||||
if (inPackage)
|
||||
opt.showQualified = false;
|
||||
boolean included = inPackage || this.opt.matchesIncludeExpression(className);
|
||||
if (!included || this.opt.matchesHideExpression(className))
|
||||
opt.setOption(HIDE);
|
||||
public void overrideForClass(Options opt, CharSequence className) {
|
||||
opt.showQualified = false;
|
||||
boolean inPackage = matcher.matches(className);
|
||||
if (inPackage)
|
||||
opt.showQualified = false;
|
||||
boolean included = inPackage || this.opt.matchesIncludeExpression(className);
|
||||
if (!included || this.opt.matchesHideExpression(className)) {
|
||||
opt.setOption(HIDE);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,26 +18,27 @@ package org.umlgraph.doclet;
|
|||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.sun.javadoc.ClassDoc;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
|
||||
/**
|
||||
* Matches classes performing a regular expression match on the qualified class
|
||||
* name
|
||||
*
|
||||
* @author wolf
|
||||
*/
|
||||
public class PatternMatcher implements ClassMatcher {
|
||||
Pattern pattern;
|
||||
|
||||
public PatternMatcher(Pattern pattern) {
|
||||
this.pattern = pattern;
|
||||
this.pattern = pattern;
|
||||
}
|
||||
|
||||
public boolean matches(ClassDoc cd) {
|
||||
return matches(cd.toString());
|
||||
public boolean matches(TypeElement cd) {
|
||||
return matches(cd.getQualifiedName());
|
||||
}
|
||||
|
||||
public boolean matches(String name) {
|
||||
return pattern.matcher(name).matches();
|
||||
public boolean matches(CharSequence name) {
|
||||
return pattern.matcher(name).matches();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,32 +9,35 @@ public enum RelationDirection {
|
|||
|
||||
/**
|
||||
* Adds the current direction
|
||||
*
|
||||
* @param d
|
||||
* @return
|
||||
*/
|
||||
public RelationDirection sum(RelationDirection d) {
|
||||
// Handle same and nones first:
|
||||
return (this == d || d == NONE) ? this : //
|
||||
this == NONE ? d : BOTH; // They are different and not none.
|
||||
// Handle same and nones first:
|
||||
return (this == d || d == NONE) ? this : //
|
||||
this == NONE ? d : BOTH; // They are different and not none.
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this direction "contains" the specified one, that is,
|
||||
* either it's equal to it, or this direction is {@link #BOTH}
|
||||
* Returns true if this direction "contains" the specified one, that is, either
|
||||
* it's equal to it, or this direction is {@link #BOTH}
|
||||
*
|
||||
* @param d
|
||||
* @return
|
||||
*/
|
||||
public boolean contains(RelationDirection d) {
|
||||
return this == BOTH ? true : (d == this);
|
||||
return this == BOTH ? true : (d == this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inverts the direction of the relation. Turns IN into OUT and vice-versa, NONE and BOTH
|
||||
* are not changed
|
||||
* Inverts the direction of the relation. Turns IN into OUT and vice-versa, NONE
|
||||
* and BOTH are not changed
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public RelationDirection inverse() {
|
||||
return this == IN ? OUT : this == OUT ? IN : this;
|
||||
return this == IN ? OUT : this == OUT ? IN : this;
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package org.umlgraph.doclet;
|
|||
|
||||
/**
|
||||
* A map from relation types to directions
|
||||
*
|
||||
* @author wolf
|
||||
*
|
||||
*/
|
||||
|
|
@ -13,38 +14,41 @@ public class RelationPattern {
|
|||
|
||||
/**
|
||||
* Creates a new pattern using the same direction for every relation kind
|
||||
*
|
||||
* @param defaultDirection The direction used to initialize this pattern
|
||||
*/
|
||||
public RelationPattern(RelationDirection defaultDirection) {
|
||||
directions = new RelationDirection[RelationType.values().length];
|
||||
for (int i = 0; i < directions.length; i++) {
|
||||
directions[i] = defaultDirection;
|
||||
}
|
||||
directions = new RelationDirection[RelationType.values().length];
|
||||
for (int i = 0; i < directions.length; i++) {
|
||||
directions[i] = defaultDirection;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds, eventually merging, a direction for the specified relation type
|
||||
*
|
||||
* @param relationType
|
||||
* @param direction
|
||||
*/
|
||||
public void addRelation(RelationType relationType, RelationDirection direction) {
|
||||
int idx = relationType.ordinal();
|
||||
directions[idx] = directions[idx].sum(direction);
|
||||
int idx = relationType.ordinal();
|
||||
directions[idx] = directions[idx].sum(direction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this patterns matches at least the direction of one
|
||||
* of the relations in the other relation patterns. Matching is defined
|
||||
* by {@linkplain RelationDirection#contains(RelationDirection)}
|
||||
* Returns true if this patterns matches at least the direction of one of the
|
||||
* relations in the other relation patterns. Matching is defined by
|
||||
* {@linkplain RelationDirection#contains(RelationDirection)}
|
||||
*
|
||||
* @param relationPattern
|
||||
* @return
|
||||
*/
|
||||
public boolean matchesOne(RelationPattern relationPattern) {
|
||||
for (int i = 0; i < directions.length; i++) {
|
||||
if (directions[i].contains(relationPattern.directions[i]))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
for (int i = 0; i < directions.length; i++) {
|
||||
if (directions[i].contains(relationPattern.directions[i]))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ public enum RelationType {
|
|||
|
||||
/** Enum constructors must be private */
|
||||
private RelationType(String style, boolean backorder) {
|
||||
this.lower = toString().toLowerCase();
|
||||
this.style = style;
|
||||
this.backorder = backorder;
|
||||
this.lower = toString().toLowerCase();
|
||||
this.style = style;
|
||||
this.backorder = backorder;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,10 +45,10 @@ public enum Shape {
|
|||
|
||||
/** Initialize the lookup index */
|
||||
static {
|
||||
for (Shape s : Shape.values()) {
|
||||
index.put(s.name(), s);
|
||||
index.put(s.name().toLowerCase(Locale.ROOT), s);
|
||||
}
|
||||
for (Shape s : Shape.values()) {
|
||||
index.put(s.name(), s);
|
||||
index.put(s.name().toLowerCase(Locale.ROOT), s);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -59,25 +59,25 @@ public enum Shape {
|
|||
* @return Shape
|
||||
*/
|
||||
public static Shape of(String s) {
|
||||
Shape shp = index.get(s);
|
||||
if (shp != null)
|
||||
return shp;
|
||||
System.err.println("Ignoring invalid shape: " + s);
|
||||
return CLASS;
|
||||
Shape shp = index.get(s);
|
||||
if (shp != null)
|
||||
return shp;
|
||||
System.err.println("Ignoring invalid shape: " + s);
|
||||
return CLASS;
|
||||
}
|
||||
|
||||
/** Enum constructor, must be private! */
|
||||
private Shape(String style) {
|
||||
this.style = style;
|
||||
this.style = style;
|
||||
}
|
||||
|
||||
/** Return the table border required for the shape */
|
||||
public String extraColumn() {
|
||||
return this == Shape.ACTIVECLASS ? ("<td rowspan=\"10\"></td>") : "";
|
||||
return this == Shape.ACTIVECLASS ? ("<td rowspan=\"10\"></td>") : "";
|
||||
}
|
||||
|
||||
/** Return the cell border required for the shape */
|
||||
public String cellBorder() {
|
||||
return this == CLASS || this == ACTIVECLASS ? "1" : "0";
|
||||
return this == CLASS || this == ACTIVECLASS ? "1" : "0";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,9 @@
|
|||
|
||||
package org.umlgraph.doclet;
|
||||
|
||||
import javax.lang.model.element.Name;
|
||||
import javax.lang.model.util.Elements;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
|
@ -31,37 +34,37 @@ import java.util.regex.Pattern;
|
|||
class StringUtil {
|
||||
/** Tokenize string s into an array */
|
||||
public static String[] tokenize(String s) {
|
||||
ArrayList<String> r = new ArrayList<String>();
|
||||
String remain = s;
|
||||
int n = 0, pos;
|
||||
ArrayList<String> r = new ArrayList<String>();
|
||||
String remain = s;
|
||||
int n = 0, pos;
|
||||
|
||||
remain = remain.trim();
|
||||
while (remain.length() > 0) {
|
||||
if (remain.startsWith("\"")) {
|
||||
// Field in quotes
|
||||
pos = remain.indexOf('"', 1);
|
||||
if (pos == -1)
|
||||
break;
|
||||
r.add(remain.substring(1, pos));
|
||||
if (pos + 1 < remain.length())
|
||||
pos++;
|
||||
} else {
|
||||
// Space-separated field
|
||||
pos = remain.indexOf(' ', 0);
|
||||
if (pos == -1) {
|
||||
r.add(remain);
|
||||
remain = "";
|
||||
} else
|
||||
r.add(remain.substring(0, pos));
|
||||
}
|
||||
remain = remain.substring(pos + 1);
|
||||
remain = remain.trim();
|
||||
// - is used as a placeholder for empy fields
|
||||
if (r.get(n).equals("-"))
|
||||
r.set(n, "");
|
||||
n++;
|
||||
}
|
||||
return r.toArray(new String[0]);
|
||||
remain = remain.trim();
|
||||
while (remain.length() > 0) {
|
||||
if (remain.startsWith("\"")) {
|
||||
// Field in quotes
|
||||
pos = remain.indexOf('"', 1);
|
||||
if (pos == -1)
|
||||
break;
|
||||
r.add(remain.substring(1, pos));
|
||||
if (pos + 1 < remain.length())
|
||||
pos++;
|
||||
} else {
|
||||
// Space-separated field
|
||||
pos = remain.indexOf(' ', 0);
|
||||
if (pos == -1) {
|
||||
r.add(remain);
|
||||
remain = "";
|
||||
} else
|
||||
r.add(remain.substring(0, pos));
|
||||
}
|
||||
remain = remain.substring(pos + 1);
|
||||
remain = remain.trim();
|
||||
// - is used as a placeholder for empy fields
|
||||
if (r.get(n).equals("-"))
|
||||
r.set(n, "");
|
||||
n++;
|
||||
}
|
||||
return r.toArray(new String[0]);
|
||||
}
|
||||
|
||||
private final static Pattern ESCAPE_BASIC_XML = Pattern.compile("[&<>]");
|
||||
|
|
@ -71,47 +74,47 @@ class StringUtil {
|
|||
* HTML entity code.
|
||||
*/
|
||||
public static String escape(String s) {
|
||||
if (ESCAPE_BASIC_XML.matcher(s).find()) {
|
||||
StringBuilder sb = new StringBuilder(s);
|
||||
for (int i = 0; i < sb.length();) {
|
||||
switch (sb.charAt(i)) {
|
||||
case '&':
|
||||
sb.replace(i, i + 1, "&");
|
||||
i += "&".length();
|
||||
break;
|
||||
case '<':
|
||||
sb.replace(i, i + 1, "<");
|
||||
i += "<".length();
|
||||
break;
|
||||
case '>':
|
||||
sb.replace(i, i + 1, ">");
|
||||
i += ">".length();
|
||||
break;
|
||||
default:
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
} else
|
||||
return s;
|
||||
if (ESCAPE_BASIC_XML.matcher(s).find()) {
|
||||
StringBuilder sb = new StringBuilder(s);
|
||||
for (int i = 0; i < sb.length();) {
|
||||
switch (sb.charAt(i)) {
|
||||
case '&':
|
||||
sb.replace(i, i + 1, "&");
|
||||
i += "&".length();
|
||||
break;
|
||||
case '<':
|
||||
sb.replace(i, i + 1, "<");
|
||||
i += "<".length();
|
||||
break;
|
||||
case '>':
|
||||
sb.replace(i, i + 1, ">");
|
||||
i += ">".length();
|
||||
break;
|
||||
default:
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
} else
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert embedded newlines into HTML line breaks
|
||||
*/
|
||||
public static String htmlNewline(String s) {
|
||||
if (s.indexOf('\n') == -1)
|
||||
return s;
|
||||
if (s.indexOf('\n') == -1)
|
||||
return s;
|
||||
|
||||
StringBuilder sb = new StringBuilder(s);
|
||||
for (int i = 0; i < sb.length();) {
|
||||
if (sb.charAt(i) == '\n') {
|
||||
sb.replace(i, i + 1, "<br/>");
|
||||
i += "<br/>".length();
|
||||
} else
|
||||
i++;
|
||||
}
|
||||
return sb.toString();
|
||||
StringBuilder sb = new StringBuilder(s);
|
||||
for (int i = 0; i < sb.length();) {
|
||||
if (sb.charAt(i) == '\n') {
|
||||
sb.replace(i, i + 1, "<br/>");
|
||||
i += "<br/>".length();
|
||||
} else
|
||||
i++;
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -119,22 +122,22 @@ class StringUtil {
|
|||
* characters.
|
||||
*/
|
||||
public static String guillemize(Options opt, String s) {
|
||||
StringBuilder r = new StringBuilder(s);
|
||||
for (int i = 0; i < r.length();)
|
||||
switch (r.charAt(i)) {
|
||||
case '<':
|
||||
r.replace(i, i + 1, opt.guilOpen);
|
||||
i += opt.guilOpen.length();
|
||||
break;
|
||||
case '>':
|
||||
r.replace(i, i + 1, opt.guilClose);
|
||||
i += opt.guilClose.length();
|
||||
break;
|
||||
default:
|
||||
i++;
|
||||
break;
|
||||
}
|
||||
return r.toString();
|
||||
StringBuilder r = new StringBuilder(s);
|
||||
for (int i = 0; i < r.length();)
|
||||
switch (r.charAt(i)) {
|
||||
case '<':
|
||||
r.replace(i, i + 1, opt.guilOpen);
|
||||
i += opt.guilOpen.length();
|
||||
break;
|
||||
case '>':
|
||||
r.replace(i, i + 1, opt.guilClose);
|
||||
i += opt.guilClose.length();
|
||||
break;
|
||||
default:
|
||||
i++;
|
||||
break;
|
||||
}
|
||||
return r.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -144,45 +147,49 @@ class StringUtil {
|
|||
* @return the wrapped <code>String</code>.
|
||||
*/
|
||||
public static String guilWrap(Options opt, String str) {
|
||||
return opt.guilOpen + str + opt.guilClose;
|
||||
return opt.guilOpen + str + opt.guilClose;
|
||||
}
|
||||
|
||||
/** Removes the template specs from a class name. */
|
||||
public static String removeTemplate(String name) {
|
||||
int openIdx = name.indexOf('<');
|
||||
if (openIdx == -1)
|
||||
return name;
|
||||
StringBuilder buf = new StringBuilder(name.length());
|
||||
for (int i = 0, depth = 0; i < name.length(); i++) {
|
||||
char c = name.charAt(i);
|
||||
if (c == '<')
|
||||
depth++;
|
||||
else if (c == '>')
|
||||
depth--;
|
||||
else if (depth == 0)
|
||||
buf.append(c);
|
||||
}
|
||||
return buf.toString();
|
||||
public static Name removeTemplate(Elements elements, Name name) {
|
||||
int openIdx = name.toString().indexOf('<');
|
||||
if (openIdx == -1) {
|
||||
return name;
|
||||
}
|
||||
StringBuilder buf = new StringBuilder(name.length());
|
||||
for (int i = 0, depth = 0; i < name.length(); i++) {
|
||||
char c = name.charAt(i);
|
||||
if (c == '<')
|
||||
depth++;
|
||||
else if (c == '>')
|
||||
depth--;
|
||||
else if (depth == 0)
|
||||
buf.append(c);
|
||||
}
|
||||
return elements.getName(buf.toString());
|
||||
}
|
||||
|
||||
public static String buildRelativePathFromClassNames(String contextPackageName, String classPackageName) {
|
||||
// path, relative to the root, of the destination class
|
||||
String[] contextClassPath = contextPackageName.split("\\.");
|
||||
String[] currClassPath = classPackageName.split("\\.");
|
||||
public static String buildRelativePathFromClassNames(Name contextPackageName, String classPackageName) {
|
||||
// path, relative to the root, of the destination class
|
||||
String[] contextClassPath = contextPackageName.toString().split("\\.");
|
||||
String[] currClassPath = classPackageName.split("\\.");
|
||||
|
||||
// compute relative path between the context and the destination
|
||||
// ... first, compute common part
|
||||
int i = 0, e = Math.min(contextClassPath.length, currClassPath.length);
|
||||
while (i < e && contextClassPath[i].equals(currClassPath[i]))
|
||||
i++;
|
||||
// ... go up with ".." to reach the common root
|
||||
StringBuilder buf = new StringBuilder(classPackageName.length());
|
||||
for (int j = i; j < contextClassPath.length; j++)
|
||||
buf.append("../");
|
||||
// ... go down from the common root to the destination
|
||||
for (int j = i; j < currClassPath.length; j++)
|
||||
buf.append(currClassPath[j]).append('/'); // Always use HTML seperators
|
||||
return buf.toString();
|
||||
// compute relative path between the context and the destination
|
||||
// ... first, compute common part
|
||||
int i = 0, e = Math.min(contextClassPath.length, currClassPath.length);
|
||||
while (i < e && contextClassPath[i].equals(currClassPath[i])) {
|
||||
i++;
|
||||
}
|
||||
// ... go up with ".." to reach the common root
|
||||
StringBuilder buf = new StringBuilder(classPackageName.length());
|
||||
for (int j = i; j < contextClassPath.length; j++) {
|
||||
buf.append("../");
|
||||
}
|
||||
// ... go down from the common root to the destination
|
||||
for (int j = i; j < currClassPath.length; j++) {
|
||||
buf.append(currClassPath[j]).append('/'); // Always use HTML seperators
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -195,28 +202,29 @@ class StringUtil {
|
|||
* users adhere to Java conventions, of beginning package names with a lowercase
|
||||
* letter.
|
||||
*
|
||||
* @param className
|
||||
* @param name
|
||||
* @return Splitting point (Either referring to a dot, or -1)
|
||||
*/
|
||||
public static int splitPackageClass(String className) {
|
||||
int gen = className.indexOf('<'); // Begin before generics.
|
||||
int end = gen >= 0 ? gen : className.length();
|
||||
int start = className.lastIndexOf('.', end);
|
||||
// No package name special cases:
|
||||
if (start < 0)
|
||||
return gen >= 0 || className.isEmpty() ? -1 //
|
||||
: Character.isLowerCase(className.charAt(0)) ? end : -1;
|
||||
int split = end;
|
||||
while (true) {
|
||||
if (Character.isLowerCase(className.charAt(start + 1)))
|
||||
return split;
|
||||
split = start; // Continue, this looks like a class name.
|
||||
if (start < 0)
|
||||
return -1;
|
||||
start = className.lastIndexOf('.', start - 1);
|
||||
}
|
||||
public static int splitPackageClass(CharSequence name) {
|
||||
String className = name.toString();
|
||||
int gen = className.indexOf('<'); // Begin before generics.
|
||||
int end = gen >= 0 ? gen : className.length();
|
||||
int start = className.lastIndexOf('.', end);
|
||||
// No package name special cases:
|
||||
if (start < 0)
|
||||
return gen >= 0 || className.isEmpty() ? -1 //
|
||||
: Character.isLowerCase(className.charAt(0)) ? end : -1;
|
||||
int split = end;
|
||||
while (true) {
|
||||
if (Character.isLowerCase(className.charAt(start + 1)))
|
||||
return split;
|
||||
split = start; // Continue, this looks like a class name.
|
||||
if (start < 0)
|
||||
return -1;
|
||||
start = className.lastIndexOf('.', start - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Format a double to a string.
|
||||
* <p>
|
||||
|
|
@ -226,6 +234,6 @@ class StringUtil {
|
|||
* @return Formatted value
|
||||
*/
|
||||
public static String fmt(double val) {
|
||||
return val == Math.round(val) ? Long.toString((long) val) : Double.toString(val);
|
||||
return val == Math.round(val) ? Long.toString((long) val) : Double.toString(val);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,35 +2,40 @@ package org.umlgraph.doclet;
|
|||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.sun.javadoc.ClassDoc;
|
||||
import com.sun.javadoc.RootDoc;
|
||||
import jdk.javadoc.doclet.DocletEnvironment;
|
||||
|
||||
import javax.lang.model.element.TypeElement;
|
||||
|
||||
import org.umlgraph.doclet.util.ElementUtil;
|
||||
|
||||
/**
|
||||
* Matches every class that extends (directly or indirectly) a class
|
||||
* matched by the regular expression provided.
|
||||
* Matches every class that extends (directly or indirectly) a class matched by
|
||||
* the regular expression provided.
|
||||
*/
|
||||
public class SubclassMatcher implements ClassMatcher {
|
||||
|
||||
protected RootDoc root;
|
||||
protected DocletEnvironment root;
|
||||
protected Pattern pattern;
|
||||
|
||||
public SubclassMatcher(RootDoc root, Pattern pattern) {
|
||||
this.root = root;
|
||||
this.pattern = pattern;
|
||||
public SubclassMatcher(DocletEnvironment root, Pattern pattern) {
|
||||
this.root = root;
|
||||
this.pattern = pattern;
|
||||
}
|
||||
|
||||
public boolean matches(ClassDoc cd) {
|
||||
// if it's the class we're looking for return
|
||||
if(pattern.matcher(cd.toString()).matches())
|
||||
return true;
|
||||
|
||||
// recurse on supeclass, if available
|
||||
return cd.superclass() == null ? false : matches(cd.superclass());
|
||||
public boolean matches(TypeElement cd) {
|
||||
// if it's the class we're looking for return
|
||||
if (pattern.matcher(cd.toString()).matches()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// recurse on superclass, if available
|
||||
TypeElement scd = ElementUtil.getTypeElement(cd.getSuperclass());
|
||||
return scd == null ? false : matches(scd);
|
||||
}
|
||||
|
||||
public boolean matches(String name) {
|
||||
ClassDoc cd = root.classNamed(name);
|
||||
return cd == null ? false : matches(cd);
|
||||
public boolean matches(CharSequence name) {
|
||||
TypeElement cd = root.getElementUtils().getTypeElement(name);
|
||||
return cd == null ? false : matches(cd);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,121 @@
|
|||
package org.umlgraph.doclet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.umlgraph.doclet.util.CommentHelper;
|
||||
|
||||
import com.sun.source.doctree.*;
|
||||
import com.sun.source.util.SimpleDocTreeVisitor;
|
||||
|
||||
/**
|
||||
* A visitor to gather the block tags found in a comment.
|
||||
*/
|
||||
public class TagScanner extends SimpleDocTreeVisitor<Void, Void> {
|
||||
|
||||
private final Map<String, List<String>> tags;
|
||||
|
||||
public TagScanner(Map<String, List<String>> tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitDocComment(DocCommentTree tree, Void p) {
|
||||
if (tree == null) {
|
||||
return null;
|
||||
}
|
||||
String body = CommentHelper.getText(tree.getFullBody());
|
||||
tags.put("comment", new ArrayList<>(List.of(body)));
|
||||
return visit(tree.getBlockTags(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitAuthor(AuthorTree node, Void p) {
|
||||
String name = node.getTagName();
|
||||
String content = node.getName().toString();
|
||||
tags.computeIfAbsent(name, n -> new ArrayList<>()).add(content);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitDeprecated(DeprecatedTree node, Void p) {
|
||||
String name = node.getTagName();
|
||||
String content = CommentHelper.getText(node.getBody());
|
||||
tags.computeIfAbsent(name, n -> new ArrayList<>()).add(content);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitProvides(ProvidesTree node, Void p) {
|
||||
String name = node.getTagName();
|
||||
String content = CommentHelper.getText(node.getDescription());
|
||||
tags.computeIfAbsent(name, n -> new ArrayList<>()).add(content);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitSince(SinceTree node, Void p) {
|
||||
String name = node.getTagName();
|
||||
String content = CommentHelper.getText(node.getBody());
|
||||
tags.computeIfAbsent(name, n -> new ArrayList<>()).add(content);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitVersion(VersionTree node, Void p) {
|
||||
String name = node.getTagName();
|
||||
String content = CommentHelper.getText(node.getBody());
|
||||
tags.computeIfAbsent(name, n -> new ArrayList<>()).add(content);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitParam(ParamTree node, Void p) {
|
||||
String name = node.getTagName();
|
||||
String content = node.getName().toString() + " " + CommentHelper.getText(node.getDescription());
|
||||
tags.computeIfAbsent(name, n -> new ArrayList<>()).add(content);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitReturn(ReturnTree node, Void p) {
|
||||
String name = node.getTagName();
|
||||
String content = CommentHelper.getText(node.getDescription());
|
||||
tags.computeIfAbsent(name, n -> new ArrayList<>()).add(content);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitSee(SeeTree node, Void p) {
|
||||
String name = node.getTagName();
|
||||
String content = CommentHelper.getText(node.getReference());
|
||||
tags.computeIfAbsent(name, n -> new ArrayList<>()).add(content);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitThrows(ThrowsTree node, Void p) {
|
||||
String name = node.getTagName();
|
||||
String content = CommentHelper.getText(node.getDescription());
|
||||
tags.computeIfAbsent(name, n -> new ArrayList<>()).add(content);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitUses(UsesTree node, Void p) {
|
||||
String name = node.getTagName();
|
||||
String content = CommentHelper.getText(node.getDescription());
|
||||
tags.computeIfAbsent(name, n -> new ArrayList<>()).add(content);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Void visitUnknownBlockTag(UnknownBlockTagTree tree, Void p) {
|
||||
String name = tree.getTagName();
|
||||
String content = CommentHelper.getText(tree.getContent());
|
||||
tags.computeIfAbsent(name, n -> new ArrayList<>()).add(content);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,8 +2,10 @@ package org.umlgraph.doclet;
|
|||
|
||||
/**
|
||||
* Options for UMLGraph class diagram generation
|
||||
*
|
||||
* @opt operations
|
||||
* @opt visibility
|
||||
* @hidden
|
||||
*/
|
||||
public class UMLOptions {}
|
||||
public class UMLOptions {
|
||||
}
|
||||
|
|
@ -20,17 +20,30 @@
|
|||
package org.umlgraph.doclet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import com.sun.javadoc.ClassDoc;
|
||||
import com.sun.javadoc.Doc;
|
||||
import com.sun.javadoc.LanguageVersion;
|
||||
import com.sun.javadoc.RootDoc;
|
||||
import jdk.javadoc.doclet.Doclet;
|
||||
import jdk.javadoc.doclet.DocletEnvironment;
|
||||
import jdk.javadoc.doclet.Reporter;
|
||||
import jdk.javadoc.doclet.StandardDoclet;
|
||||
|
||||
import javax.lang.model.SourceVersion;
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.Modifier;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.tools.Diagnostic;
|
||||
|
||||
import org.umlgraph.doclet.util.ElementUtil;
|
||||
import org.umlgraph.doclet.util.TagUtil;
|
||||
|
||||
/**
|
||||
* Doclet API implementation
|
||||
*
|
||||
* @depend - - - OptionProvider
|
||||
* @depend - - - Options
|
||||
* @depend - - - View
|
||||
|
|
@ -40,7 +53,7 @@ import com.sun.javadoc.RootDoc;
|
|||
* @version $Revision$
|
||||
* @author <a href="http://www.spinellis.gr">Diomidis Spinellis</a>
|
||||
*/
|
||||
public class UmlGraph {
|
||||
public class UmlGraph implements Doclet {
|
||||
|
||||
private static final String programName = "UmlGraph";
|
||||
private static final String docletName = "org.umlgraph.doclet.UmlGraph";
|
||||
|
|
@ -48,141 +61,195 @@ public class UmlGraph {
|
|||
/** Options used for commenting nodes */
|
||||
private static Options commentOptions;
|
||||
|
||||
/** Entry point through javadoc */
|
||||
public static boolean start(RootDoc root) throws IOException {
|
||||
Options opt = buildOptions(root);
|
||||
root.printNotice("UMLGraph doclet version " + Version.VERSION + " started");
|
||||
|
||||
View[] views = buildViews(opt, root, root);
|
||||
if(views == null)
|
||||
return false;
|
||||
if (views.length == 0)
|
||||
buildGraph(root, opt, null);
|
||||
else
|
||||
for (int i = 0; i < views.length; i++)
|
||||
buildGraph(root, views[i], null);
|
||||
return true;
|
||||
private Locale locale;
|
||||
private Reporter reporter;
|
||||
private Options options;
|
||||
private StandardDoclet standard;
|
||||
|
||||
public UmlGraph() {
|
||||
this.options = new Options();
|
||||
this.standard = new StandardDoclet();
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
PrintWriter err = new PrintWriter(System.err);
|
||||
com.sun.tools.javadoc.Main.execute(programName,
|
||||
err, err, err, docletName, args);
|
||||
@Override
|
||||
public void init(Locale locale, Reporter reporter) {
|
||||
this.locale = locale;
|
||||
this.reporter = reporter;
|
||||
}
|
||||
|
||||
public static Options getCommentOptions() {
|
||||
return commentOptions;
|
||||
@Override
|
||||
public String getName() {
|
||||
return docletName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<? extends Doclet.Option> getSupportedOptions() {
|
||||
Set<Doclet.Option> options = new HashSet<>(standard.getSupportedOptions());
|
||||
for (Doclet.Option opt : this.options.OPTIONS) {
|
||||
options.add(opt);
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SourceVersion getSupportedSourceVersion() {
|
||||
return standard.getSupportedSourceVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the base Options object.
|
||||
* This contains both the options specified on the command
|
||||
* line and the ones specified in the UMLOptions class, if available.
|
||||
* Also create the globally accessible commentOptions object.
|
||||
* Standard doclet entry point
|
||||
*
|
||||
* @param root
|
||||
* @return
|
||||
*/
|
||||
public static Options buildOptions(RootDoc root) {
|
||||
commentOptions = new Options();
|
||||
commentOptions.setOptions(root.options());
|
||||
commentOptions.setOptions(findClass(root, "UMLNoteOptions"));
|
||||
commentOptions.shape = Shape.NOTE;
|
||||
@Override
|
||||
/** Entry point through javadoc */
|
||||
public boolean run(DocletEnvironment root) {
|
||||
reporter.print(Diagnostic.Kind.NOTE, "UMLGraph doclet version " + Version.VERSION + " started");
|
||||
|
||||
Options opt = new Options();
|
||||
opt.setOptions(root.options());
|
||||
opt.setOptions(findClass(root, "UMLOptions"));
|
||||
return opt;
|
||||
List<View> views = buildViews(options, root, root);
|
||||
if (views == null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
if (views.isEmpty()) {
|
||||
buildGraph(reporter, root, options, null, null);
|
||||
} else {
|
||||
for (View view : views) {
|
||||
buildGraph(reporter, root, options, view, null);
|
||||
}
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
reporter.print(Diagnostic.Kind.ERROR, "UMLGraph doclet error : " + ioe);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static Options getCommentOptions() {
|
||||
return commentOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the base Options object. This contains both the options specified on
|
||||
* the command line and the ones specified in the UMLOptions class, if
|
||||
* available. Also create the globally accessible commentOptions object.
|
||||
*/
|
||||
public static Options buildOptions(DocletEnvironment root, Options o) {
|
||||
commentOptions = o.clone();
|
||||
commentOptions.setOptions(root.getDocTrees(), findClass(root, "UMLNoteOptions"));
|
||||
commentOptions.shape = Shape.NOTE;
|
||||
|
||||
Options opt = o.clone();
|
||||
opt.setOptions(root.getDocTrees(), findClass(root, "UMLOptions"));
|
||||
return opt;
|
||||
}
|
||||
|
||||
/** Return the ClassDoc for the specified class; null if not found. */
|
||||
private static ClassDoc findClass(RootDoc root, String name) {
|
||||
ClassDoc[] classes = root.classes();
|
||||
for (ClassDoc cd : classes)
|
||||
if(cd.name().equals(name))
|
||||
return cd;
|
||||
return null;
|
||||
private static TypeElement findClass(DocletEnvironment root, String name) {
|
||||
Set<? extends Element> classes = root.getIncludedElements();
|
||||
for (Element element : classes) {
|
||||
if (element instanceof TypeElement && ((TypeElement) element).getQualifiedName().toString().equals(name)) {
|
||||
return (TypeElement) element;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds and outputs a single graph according to the view overrides
|
||||
*/
|
||||
public static void buildGraph(RootDoc root, OptionProvider op, Doc contextDoc) throws IOException {
|
||||
if(getCommentOptions() == null)
|
||||
buildOptions(root);
|
||||
Options opt = op.getGlobalOptions();
|
||||
root.printNotice("Building " + op.getDisplayName());
|
||||
ClassDoc[] classes = root.classes();
|
||||
public static void buildGraph(Reporter reporter, DocletEnvironment root, Options options, OptionProvider op, Element contextDoc) throws IOException {
|
||||
if (getCommentOptions() == null) {
|
||||
buildOptions(root, options);
|
||||
}
|
||||
Options opt = op.getGlobalOptions();
|
||||
reporter.print(Diagnostic.Kind.NOTE, "Building " + op.getDisplayName());
|
||||
Set<? extends Element> elements = root.getIncludedElements();
|
||||
Set<TypeElement> classes = new HashSet<>();
|
||||
for (Element element : elements) {
|
||||
if (element instanceof TypeElement) {
|
||||
classes.add((TypeElement) element);
|
||||
}
|
||||
}
|
||||
|
||||
ClassGraph c = new ClassGraph(root, op, contextDoc);
|
||||
c.prologue();
|
||||
for (ClassDoc cd : classes)
|
||||
c.printClass(cd, true);
|
||||
for (ClassDoc cd : classes)
|
||||
c.printRelations(cd);
|
||||
if(opt.inferRelationships)
|
||||
for (ClassDoc cd : classes)
|
||||
c.printInferredRelations(cd);
|
||||
if(opt.inferDependencies)
|
||||
for (ClassDoc cd : classes)
|
||||
c.printInferredDependencies(cd);
|
||||
ClassGraph c = new ClassGraph(root, op, contextDoc);
|
||||
c.prologue();
|
||||
for (TypeElement cd : classes) {
|
||||
c.printClass(cd, true);
|
||||
}
|
||||
for (TypeElement cd : classes) {
|
||||
c.printRelations(cd);
|
||||
}
|
||||
if (opt.inferRelationships) {
|
||||
for (TypeElement cd : classes) {
|
||||
c.printInferredRelations(cd);
|
||||
}
|
||||
}
|
||||
if (opt.inferDependencies) {
|
||||
for (TypeElement cd : classes) {
|
||||
c.printInferredDependencies(cd);
|
||||
}
|
||||
}
|
||||
|
||||
c.printExtraClasses(root);
|
||||
c.epilogue();
|
||||
c.printExtraClasses(root);
|
||||
c.epilogue();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
*
|
||||
* @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)
|
||||
*/
|
||||
public static View[] buildViews(Options opt, RootDoc srcRootDoc, RootDoc viewRootDoc) {
|
||||
if (opt.viewName != null) {
|
||||
ClassDoc viewClass = viewRootDoc.classNamed(opt.viewName);
|
||||
if(viewClass == null) {
|
||||
System.out.println("View " + opt.viewName + " not found! Exiting without generating any output.");
|
||||
return null;
|
||||
}
|
||||
if(viewClass.tags("view").length == 0) {
|
||||
System.out.println(viewClass + " is not a view!");
|
||||
return null;
|
||||
}
|
||||
if(viewClass.isAbstract()) {
|
||||
System.out.println(viewClass + " is an abstract view, no output will be generated!");
|
||||
return null;
|
||||
}
|
||||
return new View[] { buildView(srcRootDoc, viewClass, opt) };
|
||||
} else if (opt.findViews) {
|
||||
List<View> views = new ArrayList<View>();
|
||||
ClassDoc[] classes = viewRootDoc.classes();
|
||||
public static List<View> buildViews(Options opt, DocletEnvironment srcRootDoc, DocletEnvironment viewRootDoc) {
|
||||
if (opt.viewName != null) {
|
||||
TypeElement viewClass = findClass(viewRootDoc, opt.viewName);
|
||||
if (viewClass == null) {
|
||||
System.out.println("View " + opt.viewName + " not found! Exiting without generating any output.");
|
||||
return null;
|
||||
}
|
||||
if (TagUtil.getTag(viewRootDoc, viewClass, "view").isEmpty()) {
|
||||
System.out.println(viewClass + " is not a view!");
|
||||
return null;
|
||||
}
|
||||
if (viewClass.getModifiers().contains(Modifier.ABSTRACT)) {
|
||||
System.out.println(viewClass + " is an abstract view, no output will be generated!");
|
||||
return null;
|
||||
}
|
||||
return List.of(buildView(srcRootDoc, viewClass, opt));
|
||||
} else if (opt.findViews) {
|
||||
List<View> views = new ArrayList<>();
|
||||
Set<? extends Element> classes = viewRootDoc.getIncludedElements();
|
||||
|
||||
// find view classes
|
||||
for (int i = 0; i < classes.length; i++)
|
||||
if (classes[i].tags("view").length > 0 && !classes[i].isAbstract())
|
||||
views.add(buildView(srcRootDoc, classes[i], opt));
|
||||
// find view classes
|
||||
for (Element elmt : classes) {
|
||||
if (!(elmt instanceof TypeElement)) {
|
||||
continue;
|
||||
}
|
||||
TypeElement element = (TypeElement) elmt;
|
||||
if (TagUtil.getTag(viewRootDoc, element, "view").size() > 0 && !element.getModifiers().contains(Modifier.ABSTRACT)) {
|
||||
views.add(buildView(srcRootDoc, element, opt));
|
||||
}
|
||||
}
|
||||
|
||||
return views.toArray(new View[views.size()]);
|
||||
} else
|
||||
return new View[0];
|
||||
return views;
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a view along with its parent views, recursively
|
||||
*/
|
||||
private static View buildView(RootDoc root, ClassDoc viewClass, OptionProvider provider) {
|
||||
ClassDoc superClass = viewClass.superclass();
|
||||
if(superClass == null || superClass.tags("view").length == 0)
|
||||
return new View(root, viewClass, provider);
|
||||
private static View buildView(DocletEnvironment root, TypeElement viewClass, OptionProvider provider) {
|
||||
TypeElement superClass = ElementUtil.getSuperclass(viewClass);
|
||||
if (superClass == null || TagUtil.getTag(root, superClass, "view").isEmpty()) {
|
||||
return new View(root, viewClass, provider);
|
||||
}
|
||||
|
||||
return new View(root, viewClass, buildView(root, superClass, provider));
|
||||
}
|
||||
|
||||
/** Option checking */
|
||||
public static int optionLength(String option) {
|
||||
return Options.optionLength(option);
|
||||
}
|
||||
|
||||
/** Indicate the language version we support */
|
||||
public static LanguageVersion languageVersion() {
|
||||
return LanguageVersion.JAVA_1_5;
|
||||
return new View(root, viewClass, buildView(root, superClass, provider));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,268 +3,289 @@ package org.umlgraph.doclet;
|
|||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.HashSet;
|
||||
import java.util.TreeSet;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.sun.javadoc.ClassDoc;
|
||||
import com.sun.javadoc.LanguageVersion;
|
||||
import com.sun.javadoc.PackageDoc;
|
||||
import com.sun.javadoc.RootDoc;
|
||||
import com.sun.tools.doclets.standard.Standard;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.ModuleElement;
|
||||
import javax.lang.model.element.Name;
|
||||
import javax.lang.model.element.PackageElement;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.tools.Diagnostic;
|
||||
|
||||
import org.umlgraph.doclet.util.ElementUtil;
|
||||
|
||||
import jdk.javadoc.doclet.Doclet;
|
||||
import jdk.javadoc.doclet.DocletEnvironment;
|
||||
import jdk.javadoc.doclet.Reporter;
|
||||
import jdk.javadoc.doclet.StandardDoclet;
|
||||
|
||||
/**
|
||||
* Chaining doclet that runs the standart Javadoc doclet first, and on success,
|
||||
* runs the generation of dot files by UMLGraph
|
||||
*
|
||||
* @author wolf
|
||||
*
|
||||
* @depend - - - WrappedClassDoc
|
||||
* @depend - - - WrappedRootDoc
|
||||
*/
|
||||
public class UmlGraphDoc {
|
||||
/**
|
||||
* Option check, forwards options to the standard doclet, if that one refuses them,
|
||||
* they are sent to UmlGraph
|
||||
*/
|
||||
public static int optionLength(String option) {
|
||||
int result = Standard.optionLength(option);
|
||||
if (result != 0)
|
||||
return result;
|
||||
else
|
||||
return UmlGraph.optionLength(option);
|
||||
public class UmlGraphDoc implements Doclet {
|
||||
|
||||
private Locale locale;
|
||||
private Reporter reporter;
|
||||
private Options options;
|
||||
private StandardDoclet standard;
|
||||
|
||||
public UmlGraphDoc() {
|
||||
this.options = new Options();
|
||||
this.standard = new StandardDoclet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(Locale locale, Reporter reporter) {
|
||||
this.locale = locale;
|
||||
this.reporter = reporter;
|
||||
this.standard.init(locale, reporter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.getClass().getSimpleName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<? extends Doclet.Option> getSupportedOptions() {
|
||||
Set<Doclet.Option> options = new HashSet<>(standard.getSupportedOptions());
|
||||
for (Doclet.Option opt : this.options.OPTIONS) {
|
||||
options.add(opt);
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SourceVersion getSupportedSourceVersion() {
|
||||
return standard.getSupportedSourceVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
* Standard doclet entry point
|
||||
*
|
||||
* @param root
|
||||
* @return
|
||||
*/
|
||||
public static boolean start(RootDoc root) {
|
||||
root.printNotice("UmlGraphDoc version " + Version.VERSION + ", running the standard doclet");
|
||||
Standard.start(root);
|
||||
root.printNotice("UmlGraphDoc version " + Version.VERSION + ", altering javadocs");
|
||||
try {
|
||||
String outputFolder = findOutputPath(root.options());
|
||||
@Override
|
||||
public boolean run(DocletEnvironment root) {
|
||||
reporter.print(Diagnostic.Kind.NOTE, "UmlGraphDoc version " + Version.VERSION + ", running the standard doclet");
|
||||
standard.run(root);
|
||||
reporter.print(Diagnostic.Kind.NOTE, "UmlGraphDoc version " + Version.VERSION + ", altering javadocs");
|
||||
try {
|
||||
Options opt = UmlGraph.buildOptions(root, this.options);
|
||||
// in javadoc enumerations are always printed
|
||||
opt.showEnumerations = true;
|
||||
opt.relativeLinksForSourcePackages = true;
|
||||
// enable strict matching for hide expressions
|
||||
opt.strictMatching = true;
|
||||
reporter.print(Diagnostic.Kind.NOTE, opt.toString());
|
||||
|
||||
Options opt = UmlGraph.buildOptions(root);
|
||||
opt.setOptions(root.options());
|
||||
// in javadoc enumerations are always printed
|
||||
opt.showEnumerations = true;
|
||||
opt.relativeLinksForSourcePackages = true;
|
||||
// enable strict matching for hide expressions
|
||||
opt.strictMatching = true;
|
||||
// root.printNotice(opt.toString());
|
||||
|
||||
generatePackageDiagrams(root, opt, outputFolder);
|
||||
generateContextDiagrams(root, opt, outputFolder);
|
||||
} catch(Throwable t) {
|
||||
root.printWarning("Error: " + t.toString());
|
||||
t.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
generatePackageDiagrams(root, reporter, opt, this.options.outputDirectory);
|
||||
generateContextDiagrams(root, reporter, opt, this.options.outputDirectory);
|
||||
} catch (Throwable t) {
|
||||
reporter.print(Diagnostic.Kind.WARNING, "Error: " + t.toString());
|
||||
t.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Standand doclet entry
|
||||
* @return
|
||||
* Generates the package diagrams for all of the packages that contain classes
|
||||
* among those returned by RootDoc.class()
|
||||
*/
|
||||
public static LanguageVersion languageVersion() {
|
||||
return Standard.languageVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the package diagrams for all of the packages that contain classes among those
|
||||
* returned by RootDoc.class()
|
||||
*/
|
||||
private static void generatePackageDiagrams(RootDoc root, Options opt, String outputFolder)
|
||||
throws IOException {
|
||||
Set<String> packages = new HashSet<String>();
|
||||
for (ClassDoc classDoc : root.classes()) {
|
||||
PackageDoc packageDoc = classDoc.containingPackage();
|
||||
if(!packages.contains(packageDoc.name())) {
|
||||
packages.add(packageDoc.name());
|
||||
OptionProvider view = new PackageView(outputFolder, packageDoc, root, opt);
|
||||
UmlGraph.buildGraph(root, view, packageDoc);
|
||||
runGraphviz(opt.dotExecutable, outputFolder, packageDoc.name(), packageDoc.name(), root);
|
||||
alterHtmlDocs(opt, outputFolder, packageDoc.name(), packageDoc.name(),
|
||||
"package-summary.html", Pattern.compile("(</[Hh]2>)|(<h1 title=\"Package\").*"), root);
|
||||
}
|
||||
}
|
||||
private static void generatePackageDiagrams(DocletEnvironment root, Reporter reporter, Options opt, String outputFolder) throws IOException {
|
||||
Set<Name> packages = new HashSet<>();
|
||||
for (Element classDoc : root.getIncludedElements()) {
|
||||
PackageElement packageDoc = null;
|
||||
if (classDoc instanceof PackageElement) {
|
||||
packageDoc = (PackageElement) classDoc;
|
||||
} else if (classDoc instanceof TypeElement) {
|
||||
packageDoc = ElementUtil.getPackageOf(root, classDoc);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
if (!packages.contains(packageDoc.getSimpleName())) {
|
||||
reporter.print(Diagnostic.Kind.WARNING, "Package processed " + packageDoc.getQualifiedName());
|
||||
packages.add(packageDoc.getSimpleName());
|
||||
OptionProvider view = new PackageView(outputFolder, packageDoc, root, opt);
|
||||
UmlGraph.buildGraph(reporter, root, opt, view, packageDoc);
|
||||
runGraphviz(opt.dotExecutable, outputFolder, ElementUtil.getModuleOf(root, packageDoc), packageDoc.getQualifiedName(), packageDoc.getSimpleName(), reporter);
|
||||
alterHtmlDocs(opt, outputFolder, ElementUtil.getModuleOf(root, packageDoc), packageDoc.getQualifiedName(), packageDoc.getSimpleName(), "package-summary.html",
|
||||
Pattern.compile("(</[Hh]2>)|(<h1 title=\"Package\").*"), reporter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the context diagram for a single class
|
||||
*/
|
||||
private static void generateContextDiagrams(RootDoc root, Options opt, String outputFolder)
|
||||
throws IOException {
|
||||
Set<ClassDoc> classDocs = new TreeSet<ClassDoc>(new Comparator<ClassDoc>() {
|
||||
public int compare(ClassDoc cd1, ClassDoc cd2) {
|
||||
return cd1.name().compareTo(cd2.name());
|
||||
private static void generateContextDiagrams(DocletEnvironment root, Reporter reporter, Options opt, String outputFolder) throws IOException {
|
||||
Set<TypeElement> classDocs = new TreeSet<>(new Comparator<>() {
|
||||
public int compare(TypeElement cd1, TypeElement cd2) {
|
||||
return cd1.getSimpleName().toString().compareTo(cd2.getSimpleName().toString());
|
||||
}
|
||||
});
|
||||
for (ClassDoc classDoc : root.classes())
|
||||
classDocs.add(classDoc);
|
||||
for (Element classDoc : root.getIncludedElements()) {
|
||||
if (classDoc instanceof TypeElement) {
|
||||
classDocs.add((TypeElement) classDoc);
|
||||
}
|
||||
}
|
||||
|
||||
ContextView view = null;
|
||||
for (ClassDoc classDoc : classDocs) {
|
||||
try {
|
||||
if(view == null)
|
||||
view = new ContextView(outputFolder, classDoc, root, opt);
|
||||
else
|
||||
view.setContextCenter(classDoc);
|
||||
UmlGraph.buildGraph(root, view, classDoc);
|
||||
runGraphviz(opt.dotExecutable, outputFolder, classDoc.containingPackage().name(), classDoc.name(), root);
|
||||
alterHtmlDocs(opt, outputFolder, classDoc.containingPackage().name(), classDoc.name(),
|
||||
classDoc.name() + ".html", Pattern.compile(".*(Class|Interface|Enum) " + classDoc.name() + ".*") , root);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error generating " + classDoc.name(), e);
|
||||
}
|
||||
}
|
||||
ContextView view = null;
|
||||
for (TypeElement classDoc : classDocs) {
|
||||
reporter.print(Diagnostic.Kind.WARNING, "Class processed " + classDoc.getQualifiedName());
|
||||
try {
|
||||
if (view == null) {
|
||||
view = new ContextView(outputFolder, classDoc, root, opt);
|
||||
} else {
|
||||
view.setContextCenter(classDoc);
|
||||
}
|
||||
UmlGraph.buildGraph(reporter, root, opt, view, classDoc);
|
||||
runGraphviz(opt.dotExecutable, outputFolder, ElementUtil.getModuleOf(root, classDoc), ElementUtil.getPackageOf(root, classDoc).getQualifiedName(), classDoc.getSimpleName(), reporter);
|
||||
alterHtmlDocs(opt, outputFolder, ElementUtil.getModuleOf(root, classDoc), ElementUtil.getPackageOf(root, classDoc).getQualifiedName(), classDoc.getSimpleName(),
|
||||
classDoc.getSimpleName() + ".html",
|
||||
Pattern.compile(".*(Class|Interface|Enum) " + classDoc.getSimpleName() + ".*"), reporter);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error generating " + classDoc.getSimpleName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs Graphviz dot building both a diagram (in png format) and a client side map for it.
|
||||
* Runs Graphviz dot building both a diagram (in png format) and a client side
|
||||
* map for it.
|
||||
*/
|
||||
private static void runGraphviz(String dotExecutable, String outputFolder, String packageName, String name, RootDoc root) {
|
||||
if (dotExecutable == null) {
|
||||
dotExecutable = "dot";
|
||||
}
|
||||
File dotFile = new File(outputFolder, packageName.replace(".", "/") + "/" + name + ".dot");
|
||||
File svgFile = new File(outputFolder, packageName.replace(".", "/") + "/" + name + ".svg");
|
||||
private static void runGraphviz(String dotExecutable, String outputFolder, ModuleElement module, Name packageName, Name name, Reporter reporter) {
|
||||
if (dotExecutable == null) {
|
||||
dotExecutable = "dot";
|
||||
}
|
||||
String fileName = packageName.toString().replace(".", "/") + "/" + name;
|
||||
if (Runtime.version().major() > 10 && module != null) {
|
||||
fileName = module.getQualifiedName().toString() + '/' + fileName;
|
||||
}
|
||||
File dotFile = new File(outputFolder, fileName + ".dot");
|
||||
File svgFile = new File(outputFolder, fileName + ".svg");
|
||||
|
||||
try {
|
||||
Process p = Runtime.getRuntime().exec(new String [] {
|
||||
dotExecutable,
|
||||
"-Tsvg",
|
||||
"-o",
|
||||
svgFile.getAbsolutePath(),
|
||||
dotFile.getAbsolutePath()
|
||||
});
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getErrorStream()));
|
||||
String line;
|
||||
while((line = reader.readLine()) != null)
|
||||
root.printWarning(line);
|
||||
int result = p.waitFor();
|
||||
if (result != 0)
|
||||
root.printWarning("Errors running Graphviz on " + dotFile);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.err.println("Ensure that dot is in your path and that its path does not contain spaces");
|
||||
}
|
||||
try {
|
||||
Process p = Runtime.getRuntime().exec(new String[] { dotExecutable, "-Tsvg", "-o",
|
||||
svgFile.getAbsolutePath(), dotFile.getAbsolutePath() });
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getErrorStream()));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
reporter.print(Diagnostic.Kind.WARNING, line);
|
||||
}
|
||||
int result = p.waitFor();
|
||||
if (result != 0) {
|
||||
reporter.print(Diagnostic.Kind.WARNING, "Errors running Graphviz on " + dotFile);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.err.println("Ensure that dot is in your path and that its path does not contain spaces");
|
||||
}
|
||||
}
|
||||
|
||||
//Format string for the uml image div tag.
|
||||
private static final String UML_DIV_TAG =
|
||||
"<div align=\"center\">" +
|
||||
"<object width=\"100%%\" height=\"100%%\" type=\"image/svg+xml\" data=\"%1$s.svg\" alt=\"Package class diagram package %1$s\" border=0></object>" +
|
||||
"</div>";
|
||||
|
||||
private static final String UML_AUTO_SIZED_DIV_TAG =
|
||||
"<div align=\"center\">" +
|
||||
"<object type=\"image/svg+xml\" data=\"%1$s.svg\" alt=\"Package class diagram package %1$s\" border=0></object>" +
|
||||
"</div>";
|
||||
|
||||
// Format string for the uml image div tag.
|
||||
private static final String UML_DIV_TAG = "<div align=\"center\">"
|
||||
+ "<object width=\"100%%\" height=\"100%%\" type=\"image/svg+xml\" data=\"%1$s.svg\" alt=\"Package class diagram package %1$s\" border=0></object>"
|
||||
+ "</div>";
|
||||
|
||||
private static final String UML_AUTO_SIZED_DIV_TAG = "<div align=\"center\">"
|
||||
+ "<object type=\"image/svg+xml\" data=\"%1$s.svg\" alt=\"Package class diagram package %1$s\" border=0></object>"
|
||||
+ "</div>";
|
||||
|
||||
private static final String EXPANDABLE_UML_STYLE = "font-family: Arial,Helvetica,sans-serif;font-size: 1.5em; display: block; width: 250px; height: 20px; background: #009933; padding: 5px; text-align: center; border-radius: 8px; color: white; font-weight: bold;";
|
||||
|
||||
//Format string for the java script tag.
|
||||
private static final String EXPANDABLE_UML =
|
||||
"<script type=\"text/javascript\">\n" +
|
||||
"function show() {\n" +
|
||||
" document.getElementById(\"uml\").innerHTML = \n" +
|
||||
" \'<a style=\"" + EXPANDABLE_UML_STYLE + "\" href=\"javascript:hide()\">%3$s</a>\' +\n" +
|
||||
" \'%1$s\';\n" +
|
||||
"}\n" +
|
||||
"function hide() {\n" +
|
||||
" document.getElementById(\"uml\").innerHTML = \n" +
|
||||
" \'<a style=\"" + EXPANDABLE_UML_STYLE + "\" href=\"javascript:show()\">%2$s</a>\' ;\n" +
|
||||
"}\n" +
|
||||
"</script>\n" +
|
||||
"<div id=\"uml\" >\n" +
|
||||
" <a href=\"javascript:show()\">\n" +
|
||||
" <a style=\"" + EXPANDABLE_UML_STYLE + "\" href=\"javascript:show()\">%2$s</a> \n" +
|
||||
"</div>";
|
||||
|
||||
/**
|
||||
* Takes an HTML file, looks for the first instance of the specified insertion point, and
|
||||
* inserts the diagram image reference and a client side map in that point.
|
||||
*/
|
||||
private static void alterHtmlDocs(Options opt, String outputFolder, String packageName, String className,
|
||||
String htmlFileName, Pattern insertPointPattern, RootDoc root) throws IOException {
|
||||
// setup files
|
||||
File output = new File(outputFolder, packageName.replace(".", "/"));
|
||||
File htmlFile = new File(output, htmlFileName);
|
||||
File alteredFile = new File(htmlFile.getAbsolutePath() + ".uml");
|
||||
if (!htmlFile.exists()) {
|
||||
System.err.println("Expected file not found: " + htmlFile.getAbsolutePath());
|
||||
return;
|
||||
}
|
||||
|
||||
// parse & rewrite
|
||||
BufferedWriter writer = null;
|
||||
BufferedReader reader = null;
|
||||
boolean matched = false;
|
||||
try {
|
||||
writer = new BufferedWriter(new OutputStreamWriter(new
|
||||
FileOutputStream(alteredFile), opt.outputEncoding));
|
||||
reader = new BufferedReader(new InputStreamReader(new
|
||||
FileInputStream(htmlFile), opt.outputEncoding));
|
||||
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
writer.write(line);
|
||||
writer.newLine();
|
||||
if (!matched && insertPointPattern.matcher(line).matches()) {
|
||||
matched = true;
|
||||
|
||||
String tag;
|
||||
if (opt.autoSize)
|
||||
tag = String.format(UML_AUTO_SIZED_DIV_TAG, className);
|
||||
else
|
||||
tag = String.format(UML_DIV_TAG, className);
|
||||
if (opt.collapsibleDiagrams)
|
||||
tag = String.format(EXPANDABLE_UML, tag, "Show UML class diagram", "Hide UML class diagram");
|
||||
writer.write("<!-- UML diagram added by UMLGraph version " +
|
||||
Version.VERSION +
|
||||
" (http://www.spinellis.gr/umlgraph/) -->");
|
||||
writer.newLine();
|
||||
writer.write(tag);
|
||||
writer.newLine();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (writer != null)
|
||||
writer.close();
|
||||
if (reader != null)
|
||||
reader.close();
|
||||
}
|
||||
|
||||
// if altered, delete old file and rename new one to the old file name
|
||||
if (matched) {
|
||||
htmlFile.delete();
|
||||
alteredFile.renameTo(htmlFile);
|
||||
} else {
|
||||
root.printNotice("Warning, could not find a line that matches the pattern '" + insertPointPattern.pattern()
|
||||
+ "'.\n Class diagram reference not inserted");
|
||||
alteredFile.delete();
|
||||
}
|
||||
}
|
||||
// Format string for the java script tag.
|
||||
private static final String EXPANDABLE_UML = "<script type=\"text/javascript\">\n" + "function show() {\n"
|
||||
+ " document.getElementById(\"uml\").innerHTML = \n" + " \'<a style=\"" + EXPANDABLE_UML_STYLE
|
||||
+ "\" href=\"javascript:hide()\">%3$s</a>\' +\n" + " \'%1$s\';\n" + "}\n" + "function hide() {\n"
|
||||
+ " document.getElementById(\"uml\").innerHTML = \n" + " \'<a style=\"" + EXPANDABLE_UML_STYLE
|
||||
+ "\" href=\"javascript:show()\">%2$s</a>\' ;\n" + "}\n" + "</script>\n" + "<div id=\"uml\" >\n"
|
||||
+ " <a href=\"javascript:show()\">\n" + " <a style=\"" + EXPANDABLE_UML_STYLE
|
||||
+ "\" href=\"javascript:show()\">%2$s</a> \n" + "</div>";
|
||||
|
||||
/**
|
||||
* Returns the output path specified on the javadoc options
|
||||
* Takes an HTML file, looks for the first instance of the specified insertion
|
||||
* point, and inserts the diagram image reference and a client side map in that
|
||||
* point.
|
||||
*/
|
||||
private static String findOutputPath(String[][] options) {
|
||||
for (int i = 0; i < options.length; i++) {
|
||||
if (options[i][0].equals("-d"))
|
||||
return options[i][1];
|
||||
}
|
||||
return ".";
|
||||
private static void alterHtmlDocs(Options opt, String outputFolder, ModuleElement module, Name packageName, Name className,
|
||||
String htmlFileName, Pattern insertPointPattern, Reporter reporter) throws IOException {
|
||||
// setup files
|
||||
String prefix = Runtime.version().major() > 10 && module != null ? module.getQualifiedName().toString() + '/' : "";
|
||||
File output = new File(outputFolder, prefix + packageName.toString().replace(".", "/"));
|
||||
File htmlFile = new File(output, htmlFileName);
|
||||
File alteredFile = new File(htmlFile.getAbsolutePath() + ".uml");
|
||||
if (!htmlFile.exists()) {
|
||||
System.err.println("Expected file not found: " + htmlFile.getAbsolutePath());
|
||||
return;
|
||||
}
|
||||
|
||||
// parse & rewrite
|
||||
BufferedWriter writer = null;
|
||||
BufferedReader reader = null;
|
||||
boolean matched = false;
|
||||
try {
|
||||
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(alteredFile), opt.outputEncoding));
|
||||
reader = new BufferedReader(new InputStreamReader(new FileInputStream(htmlFile), opt.outputEncoding));
|
||||
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
writer.write(line);
|
||||
writer.newLine();
|
||||
if (!matched && insertPointPattern.matcher(line).matches()) {
|
||||
matched = true;
|
||||
|
||||
String tag;
|
||||
if (opt.autoSize) {
|
||||
tag = String.format(UML_AUTO_SIZED_DIV_TAG, className);
|
||||
} else {
|
||||
tag = String.format(UML_DIV_TAG, className);
|
||||
}
|
||||
if (opt.collapsibleDiagrams) {
|
||||
tag = String.format(EXPANDABLE_UML, tag, "Show UML class diagram", "Hide UML class diagram");
|
||||
}
|
||||
writer.write("<!-- UML diagram added by UMLGraph version " + Version.VERSION + " (http://www.spinellis.gr/umlgraph/) -->");
|
||||
writer.newLine();
|
||||
writer.write(tag);
|
||||
writer.newLine();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (writer != null) {
|
||||
writer.close();
|
||||
}
|
||||
if (reader != null) {
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
|
||||
// if altered, delete old file and rename new one to the old file name
|
||||
if (matched) {
|
||||
htmlFile.delete();
|
||||
alteredFile.renameTo(htmlFile);
|
||||
} else {
|
||||
reporter.print(Diagnostic.Kind.NOTE, "Warning, could not find a line that matches the pattern '"
|
||||
+ insertPointPattern.pattern() + "'.\n Class diagram reference not inserted");
|
||||
alteredFile.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
/* Automatically generated file */
|
||||
package org.umlgraph.doclet;
|
||||
class Version { public static String VERSION = "R5_7_2-60-g0e99a6";}
|
||||
|
||||
|
||||
class Version {
|
||||
public static String VERSION = "R5_7_2-60-g0e99a6";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,15 +23,19 @@ import java.util.Map;
|
|||
import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
import com.sun.javadoc.ClassDoc;
|
||||
import com.sun.javadoc.RootDoc;
|
||||
import com.sun.javadoc.Tag;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
|
||||
import org.umlgraph.doclet.util.TagUtil;
|
||||
|
||||
import jdk.javadoc.doclet.DocletEnvironment;
|
||||
import com.sun.source.util.DocTrees;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @depend - - - Options
|
||||
|
|
@ -43,131 +47,137 @@ import com.sun.javadoc.Tag;
|
|||
*
|
||||
*/
|
||||
public class View implements OptionProvider {
|
||||
Map<ClassMatcher, List<String[]>> optionOverrides = new LinkedHashMap<ClassMatcher, List<String[]>>();
|
||||
ClassDoc viewDoc;
|
||||
Map<ClassMatcher, List<String[]>> optionOverrides = new LinkedHashMap<>();
|
||||
TypeElement viewDoc;
|
||||
OptionProvider provider;
|
||||
List<String[]> globalOptions;
|
||||
RootDoc root;
|
||||
DocletEnvironment root;
|
||||
|
||||
/**
|
||||
* Builds a view given the class that contains its definition
|
||||
*/
|
||||
public View(RootDoc root, ClassDoc c, OptionProvider provider) {
|
||||
this.viewDoc = c;
|
||||
this.provider = provider;
|
||||
this.root = root;
|
||||
Tag[] tags = c.tags();
|
||||
ClassMatcher currMatcher = null;
|
||||
// parse options, get the global ones, and build a map of the
|
||||
// pattern matched overrides
|
||||
globalOptions = new ArrayList<String[]>();
|
||||
for (int i = 0; i < tags.length; i++) {
|
||||
if (tags[i].name().equals("@match")) {
|
||||
currMatcher = buildMatcher(tags[i].text());
|
||||
if(currMatcher != null) {
|
||||
optionOverrides.put(currMatcher, new ArrayList<String[]>());
|
||||
}
|
||||
} else if (tags[i].name().equals("@opt")) {
|
||||
String[] opts = StringUtil.tokenize(tags[i].text());
|
||||
opts[0] = "-" + opts[0];
|
||||
if (currMatcher == null) {
|
||||
globalOptions.add(opts);
|
||||
} else {
|
||||
optionOverrides.get(currMatcher).add(opts);
|
||||
}
|
||||
}
|
||||
}
|
||||
public View(DocletEnvironment root, TypeElement c, OptionProvider provider) {
|
||||
this.viewDoc = c;
|
||||
this.provider = provider;
|
||||
this.root = root;
|
||||
Map<String, List<String>> tags = TagUtil.getTags(root, viewDoc);
|
||||
ClassMatcher currMatcher = null;
|
||||
// parse options, get the global ones, and build a map of the
|
||||
// pattern matched overrides
|
||||
globalOptions = new ArrayList<String[]>();
|
||||
if (tags.get("match") != null) {
|
||||
for (String text : tags.get("match")) {
|
||||
currMatcher = buildMatcher(text);
|
||||
if (currMatcher != null) {
|
||||
optionOverrides.put(currMatcher, new ArrayList<>());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (tags.get("opt") != null) {
|
||||
for (String text : tags.get("opt")) {
|
||||
String[] opts = StringUtil.tokenize(text);
|
||||
opts[0] = "-" + opts[0];
|
||||
if (currMatcher == null) {
|
||||
globalOptions.add(opts);
|
||||
} else {
|
||||
optionOverrides.get(currMatcher).add(opts);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Factory method that builds the appropriate matcher for @match tags
|
||||
*/
|
||||
private ClassMatcher buildMatcher(String tagText) {
|
||||
// check there are at least @match <type> and a parameter
|
||||
String[] strings = StringUtil.tokenize(tagText);
|
||||
if (strings.length < 2) {
|
||||
System.err.println("Skipping uncomplete @match tag, type missing: " + tagText + " in view " + viewDoc);
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
if (strings[0].equals("class")) {
|
||||
return new PatternMatcher(Pattern.compile(strings[1]));
|
||||
} else if (strings[0].equals("context")) {
|
||||
return new ContextMatcher(root, Pattern.compile(strings[1]), getGlobalOptions(),
|
||||
false);
|
||||
} else if (strings[0].equals("outgoingContext")) {
|
||||
return new ContextMatcher(root, Pattern.compile(strings[1]), getGlobalOptions(),
|
||||
false);
|
||||
} else if (strings[0].equals("interface")) {
|
||||
return new InterfaceMatcher(root, Pattern.compile(strings[1]));
|
||||
} else if (strings[0].equals("subclass")) {
|
||||
return new SubclassMatcher(root, Pattern.compile(strings[1]));
|
||||
} else {
|
||||
System.err.println("Skipping @match tag, unknown match type, in view " + viewDoc);
|
||||
}
|
||||
} catch (PatternSyntaxException pse) {
|
||||
System.err.println("Skipping @match tag due to invalid regular expression '" + tagText
|
||||
+ "'" + " in view " + viewDoc);
|
||||
} catch (Exception e) {
|
||||
System.err.println("Skipping @match tag due to an internal error '" + tagText
|
||||
+ "'" + " in view " + viewDoc);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// check there are at least @match <type> and a parameter
|
||||
String[] strings = StringUtil.tokenize(tagText);
|
||||
if (strings.length < 2) {
|
||||
System.err.println("Skipping uncomplete @match tag, type missing: " + tagText + " in view " + viewDoc);
|
||||
return null;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
try {
|
||||
if (strings[0].equals("class")) {
|
||||
return new PatternMatcher(Pattern.compile(strings[1]));
|
||||
} else if (strings[0].equals("context")) {
|
||||
return new ContextMatcher(root, Pattern.compile(strings[1]), getGlobalOptions(), false);
|
||||
} else if (strings[0].equals("outgoingContext")) {
|
||||
return new ContextMatcher(root, Pattern.compile(strings[1]), getGlobalOptions(), false);
|
||||
} else if (strings[0].equals("interface")) {
|
||||
return new InterfaceMatcher(root, Pattern.compile(strings[1]));
|
||||
} else if (strings[0].equals("subclass")) {
|
||||
return new SubclassMatcher(root, Pattern.compile(strings[1]));
|
||||
} else {
|
||||
System.err.println("Skipping @match tag, unknown match type, in view " + viewDoc);
|
||||
}
|
||||
} catch (PatternSyntaxException pse) {
|
||||
System.err.println("Skipping @match tag due to invalid regular expression '" + tagText + "'" + " in view " + viewDoc);
|
||||
} catch (Exception e) {
|
||||
System.err.println("Skipping @match tag due to an internal error '" + tagText + "'" + " in view " + viewDoc);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// OptionProvider methods
|
||||
// ----------------------------------------------------------------
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
public Options getOptionsFor(ClassDoc cd) {
|
||||
Options localOpt = getGlobalOptions();
|
||||
overrideForClass(localOpt, cd);
|
||||
localOpt.setOptions(cd);
|
||||
return localOpt;
|
||||
public Options getOptionsFor(DocTrees dt, TypeElement cd) {
|
||||
Options localOpt = getGlobalOptions();
|
||||
overrideForClass(localOpt, cd);
|
||||
localOpt.setOptions(dt, cd);
|
||||
return localOpt;
|
||||
}
|
||||
|
||||
public Options getOptionsFor(String name) {
|
||||
Options localOpt = getGlobalOptions();
|
||||
overrideForClass(localOpt, name);
|
||||
return localOpt;
|
||||
public Options getOptionsFor(CharSequence name) {
|
||||
Options localOpt = getGlobalOptions();
|
||||
overrideForClass(localOpt, name);
|
||||
return localOpt;
|
||||
}
|
||||
|
||||
public Options getGlobalOptions() {
|
||||
Options go = provider.getGlobalOptions();
|
||||
|
||||
boolean outputSet = false;
|
||||
for (String[] opts : globalOptions) {
|
||||
if (Options.matchOption(opts[0], "output"))
|
||||
outputSet = true;
|
||||
go.setOption(opts);
|
||||
}
|
||||
if (!outputSet)
|
||||
go.setOption(new String[] { "output", viewDoc.name() + ".dot" });
|
||||
|
||||
return go;
|
||||
Options go = provider.getGlobalOptions();
|
||||
|
||||
boolean outputSet = false;
|
||||
for (String[] opts : globalOptions) {
|
||||
if (Options.matchOption(opts[0], "output")) {
|
||||
outputSet = true;
|
||||
}
|
||||
go.setOption(opts);
|
||||
}
|
||||
if (!outputSet) {
|
||||
go.setOption(new String[] { "output", viewDoc.getSimpleName() + ".dot" });
|
||||
}
|
||||
|
||||
return go;
|
||||
}
|
||||
|
||||
public void overrideForClass(Options opt, ClassDoc cd) {
|
||||
provider.overrideForClass(opt, cd);
|
||||
for (ClassMatcher cm : optionOverrides.keySet())
|
||||
if(cm.matches(cd))
|
||||
for (String[] override : optionOverrides.get(cm))
|
||||
opt.setOption(override);
|
||||
public void overrideForClass(Options opt, TypeElement cd) {
|
||||
provider.overrideForClass(opt, cd);
|
||||
for (ClassMatcher cm : optionOverrides.keySet()) {
|
||||
if (cm.matches(cd)) {
|
||||
for (String[] override : optionOverrides.get(cm)) {
|
||||
opt.setOption(override);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void overrideForClass(Options opt, String className) {
|
||||
provider.overrideForClass(opt, className);
|
||||
for (ClassMatcher cm : optionOverrides.keySet())
|
||||
if(cm.matches(className))
|
||||
for (String[] override : optionOverrides.get(cm))
|
||||
opt.setOption(override);
|
||||
public void overrideForClass(Options opt, CharSequence className) {
|
||||
provider.overrideForClass(opt, className);
|
||||
for (ClassMatcher cm : optionOverrides.keySet()) {
|
||||
if (cm.matches(className)) {
|
||||
for (String[] override : optionOverrides.get(cm)) {
|
||||
opt.setOption(override);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return "view " + viewDoc.name();
|
||||
return "view " + viewDoc.getSimpleName();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,11 +18,15 @@
|
|||
*/
|
||||
package org.umlgraph.doclet;
|
||||
|
||||
import com.sun.javadoc.ProgramElementDoc;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.Modifier;
|
||||
|
||||
/**
|
||||
* Enumerates the possible visibilities in a Java program. For brevity, package
|
||||
* private visibility is referred as PACKAGE.
|
||||
*
|
||||
* @author wolf
|
||||
*/
|
||||
public enum Visibility {
|
||||
|
|
@ -31,17 +35,19 @@ public enum Visibility {
|
|||
final public String symbol;
|
||||
|
||||
private Visibility(String symbol) {
|
||||
this.symbol = symbol;
|
||||
this.symbol = symbol;
|
||||
}
|
||||
|
||||
public static Visibility get(ProgramElementDoc doc) {
|
||||
if (doc.isPrivate())
|
||||
return PRIVATE;
|
||||
else if (doc.isPackagePrivate())
|
||||
return PACKAGE;
|
||||
else if (doc.isProtected())
|
||||
return PROTECTED;
|
||||
else
|
||||
return PUBLIC;
|
||||
public static Visibility get(Element doc) {
|
||||
Set<Modifier> mods = doc.getModifiers();
|
||||
if (mods.contains(Modifier.PRIVATE)) {
|
||||
return PRIVATE;
|
||||
} else if (mods.contains(Modifier.PROTECTED)) {
|
||||
return PROTECTED;
|
||||
} else if (mods.contains(Modifier.PUBLIC)) {
|
||||
return PUBLIC;
|
||||
} else {
|
||||
return PACKAGE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,168 @@
|
|||
package org.umlgraph.doclet.util;
|
||||
|
||||
import static com.sun.source.doctree.DocTree.Kind.CODE;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.source.doctree.AttributeTree;
|
||||
import com.sun.source.doctree.DocTree;
|
||||
import com.sun.source.doctree.EndElementTree;
|
||||
import com.sun.source.doctree.EntityTree;
|
||||
import com.sun.source.doctree.LinkTree;
|
||||
import com.sun.source.doctree.LiteralTree;
|
||||
import com.sun.source.doctree.ReferenceTree;
|
||||
import com.sun.source.doctree.SeeTree;
|
||||
import com.sun.source.doctree.SerialTree;
|
||||
import com.sun.source.doctree.StartElementTree;
|
||||
import com.sun.source.doctree.TextTree;
|
||||
import com.sun.source.doctree.UnknownBlockTagTree;
|
||||
import com.sun.source.doctree.ValueTree;
|
||||
import com.sun.source.doctree.AttributeTree.ValueKind;
|
||||
import com.sun.source.util.SimpleDocTreeVisitor;
|
||||
|
||||
public class CommentHelper {
|
||||
public static final String SPACER = " ";
|
||||
|
||||
public static String getText(List<? extends DocTree> list) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (DocTree dt : list) {
|
||||
sb.append(getText0(dt));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String getText(DocTree dt) {
|
||||
return getText0(dt).toString();
|
||||
}
|
||||
|
||||
private static StringBuilder getText0(DocTree dt) {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
new SimpleDocTreeVisitor<Void, Void>() {
|
||||
@Override
|
||||
public Void visitAttribute(AttributeTree node, Void p) {
|
||||
sb.append(SPACER).append(node.getName());
|
||||
if (node.getValueKind() == ValueKind.EMPTY) {
|
||||
return null;
|
||||
}
|
||||
|
||||
sb.append("=");
|
||||
String quote;
|
||||
switch (node.getValueKind()) {
|
||||
case DOUBLE:
|
||||
quote = "\"";
|
||||
break;
|
||||
case SINGLE:
|
||||
quote = "\'";
|
||||
break;
|
||||
default:
|
||||
quote = "";
|
||||
break;
|
||||
}
|
||||
sb.append(quote);
|
||||
node.getValue().stream().forEach((dt) -> {
|
||||
dt.accept(this, null);
|
||||
});
|
||||
sb.append(quote);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitEndElement(EndElementTree node, Void p) {
|
||||
sb.append("</")
|
||||
.append(node.getName())
|
||||
.append(">");
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitEntity(EntityTree node, Void p) {
|
||||
sb.append(node.toString());
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitLink(LinkTree node, Void p) {
|
||||
if (node.getReference() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
node.getReference().accept(this, null);
|
||||
node.getLabel().stream().forEach((dt) -> {
|
||||
dt.accept(this, null);
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitLiteral(LiteralTree node, Void p) {
|
||||
if (node.getKind() == CODE) {
|
||||
sb.append("<").append(node.getKind().tagName).append(">");
|
||||
}
|
||||
sb.append(node.getBody().toString());
|
||||
if (node.getKind() == CODE) {
|
||||
sb.append("</").append(node.getKind().tagName).append(">");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitReference(ReferenceTree node, Void p) {
|
||||
sb.append(node.getSignature());
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitSee(SeeTree node, Void p) {
|
||||
node.getReference().stream().forEach((dt) -> {
|
||||
dt.accept(this, null);
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitSerial(SerialTree node, Void p) {
|
||||
node.getDescription().stream().forEach((dt) -> {
|
||||
dt.accept(this, null);
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitStartElement(StartElementTree node, Void p) {
|
||||
sb.append("<");
|
||||
sb.append(node.getName());
|
||||
node.getAttributes().stream().forEach((dt) -> {
|
||||
dt.accept(this, null);
|
||||
});
|
||||
sb.append((node.isSelfClosing() ? "/>" : ">"));
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitText(TextTree node, Void p) {
|
||||
sb.append(node.getBody());
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitUnknownBlockTag(UnknownBlockTagTree node, Void p) {
|
||||
node.getContent().stream().forEach((dt) -> {
|
||||
dt.accept(this, null);
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitValue(ValueTree node, Void p) {
|
||||
return node.getReference().accept(this, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void defaultAction(DocTree node, Void p) {
|
||||
sb.append(node.toString());
|
||||
return null;
|
||||
}
|
||||
}.visit(dt, null);
|
||||
return sb;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,159 @@
|
|||
package org.umlgraph.doclet.util;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.ElementKind;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.ModuleElement;
|
||||
import javax.lang.model.element.PackageElement;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.element.VariableElement;
|
||||
import javax.lang.model.type.ArrayType;
|
||||
import javax.lang.model.type.DeclaredType;
|
||||
import javax.lang.model.type.TypeKind;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
import javax.lang.model.util.ElementFilter;
|
||||
import javax.lang.model.util.Elements;
|
||||
import javax.lang.model.util.Types;
|
||||
|
||||
import jdk.javadoc.doclet.DocletEnvironment;
|
||||
|
||||
public class ElementUtil {
|
||||
|
||||
public static CharSequence getSimpleName(Types types, TypeMirror t) {
|
||||
if (t instanceof ArrayType) {
|
||||
return getSimpleName(types, ((ArrayType) t).getComponentType()) + "[]";
|
||||
}
|
||||
if (t.getKind().isPrimitive()) {
|
||||
return t.getKind().name().toLowerCase();
|
||||
}
|
||||
Element element = types.asElement(t);
|
||||
if (element != null) {
|
||||
return element.getSimpleName();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static CharSequence getQualifiedName(Types types, TypeMirror t) {
|
||||
if (t instanceof ArrayType) {
|
||||
return getQualifiedName(types, ((ArrayType) t).getComponentType()) + "[]";
|
||||
}
|
||||
if (t.getKind().isPrimitive()) {
|
||||
return t.getKind().name().toLowerCase();
|
||||
}
|
||||
Element element = types.asElement(t);
|
||||
if (element instanceof TypeElement) {
|
||||
return ((TypeElement) element).getQualifiedName();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static TypeElement containingTypeElement(Element c) {
|
||||
if (c instanceof VariableElement) {
|
||||
Element enclosing = c.getEnclosingElement();
|
||||
return enclosing instanceof TypeElement ? (TypeElement) enclosing : null;
|
||||
} else if (c instanceof ExecutableElement) {
|
||||
Element enclosing = c.getEnclosingElement();
|
||||
return enclosing instanceof TypeElement ? (TypeElement) enclosing : null;
|
||||
}
|
||||
if (c == null) {
|
||||
System.err.println("containingElement will return null for null element");
|
||||
return null;
|
||||
}
|
||||
System.err.println("containingElement will return null for kind " + c.getKind() + " class " + c.getClass() + " name " + c.getSimpleName());
|
||||
return null;
|
||||
}
|
||||
|
||||
public static TypeElement getTypeElement(TypeMirror clazz) {
|
||||
if (clazz == null || clazz.getKind() == TypeKind.NONE) {
|
||||
return null;
|
||||
}
|
||||
if (clazz instanceof ArrayType) {
|
||||
return getTypeElement(((ArrayType) clazz).getComponentType());
|
||||
}
|
||||
if (!(clazz instanceof DeclaredType)) {
|
||||
return null;
|
||||
}
|
||||
Element scd = ((DeclaredType) clazz).asElement();
|
||||
return scd instanceof TypeElement ? (TypeElement) scd : null;
|
||||
}
|
||||
|
||||
public static TypeMirror getSuperclassType(DeclaredType pt) {
|
||||
return pt.asElement() instanceof TypeElement ? ((TypeElement) pt.asElement()).getSuperclass() : null;
|
||||
}
|
||||
|
||||
public static TypeElement getSuperclass(TypeElement element) {
|
||||
return getTypeElement(element.getSuperclass());
|
||||
}
|
||||
|
||||
public static List<? extends TypeMirror> getInterfacesTypes(TypeElement element) {
|
||||
return element.getInterfaces();
|
||||
}
|
||||
|
||||
public static List<TypeElement> getInterfaces(TypeElement element) {
|
||||
List<? extends TypeMirror> interfaces = getInterfacesTypes(element);
|
||||
return interfaces.stream().map(i -> getTypeElement(i)).filter(i -> i != null).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static ModuleElement getModuleOf(DocletEnvironment root, Element element) {
|
||||
return getModuleOf(root.getElementUtils(), element);
|
||||
}
|
||||
|
||||
public static ModuleElement getModuleOf(Elements elements, Element element) {
|
||||
if (element == null) {
|
||||
return null;
|
||||
}
|
||||
if (element instanceof ModuleElement) {
|
||||
return (ModuleElement) element;
|
||||
}
|
||||
return elements.getModuleOf(element);
|
||||
}
|
||||
|
||||
public static PackageElement getPackageOf(DocletEnvironment root, Element element) {
|
||||
return getPackageOf(root.getElementUtils(), element);
|
||||
}
|
||||
|
||||
public static PackageElement getPackageOf(Elements elements, Element element) {
|
||||
if (element == null) {
|
||||
return null;
|
||||
}
|
||||
if (element instanceof PackageElement) {
|
||||
return (PackageElement) element;
|
||||
}
|
||||
return elements.getPackageOf(element);
|
||||
}
|
||||
|
||||
public static List<VariableElement> getFields(TypeElement element) {
|
||||
List<? extends Element> enclosed = element.getEnclosedElements();
|
||||
return ElementFilter.fieldsIn(enclosed).stream().filter(v -> v.getKind() == ElementKind.FIELD).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static List<VariableElement> getEnumConstants(TypeElement element) {
|
||||
List<? extends Element> enclosed = element.getEnclosedElements();
|
||||
return ElementFilter.fieldsIn(enclosed).stream().filter(v -> v.getKind() == ElementKind.ENUM_CONSTANT).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static List<ExecutableElement> getMethods(TypeElement element) {
|
||||
List<? extends Element> enclosed = element.getEnclosedElements();
|
||||
return ElementFilter.methodsIn(enclosed);
|
||||
}
|
||||
|
||||
public static List<ExecutableElement> getConstructors(TypeElement element) {
|
||||
List<? extends Element> enclosed = element.getEnclosedElements();
|
||||
return ElementFilter.constructorsIn(enclosed);
|
||||
}
|
||||
|
||||
public static String dimensions(TypeMirror type) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
// First append root component type
|
||||
TypeMirror t = type;
|
||||
while (t.getKind() == TypeKind.ARRAY) {
|
||||
sb.append("[]");
|
||||
t = ((ArrayType) t).getComponentType();
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
package org.umlgraph.doclet.util;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.lang.model.element.Element;
|
||||
|
||||
import org.umlgraph.doclet.TagScanner;
|
||||
|
||||
import com.sun.source.doctree.DocCommentTree;
|
||||
import com.sun.source.util.DocTrees;
|
||||
|
||||
import jdk.javadoc.doclet.DocletEnvironment;
|
||||
|
||||
public class TagUtil {
|
||||
|
||||
public static Map<String, List<String>> getTags(DocletEnvironment root, Element c) {
|
||||
return getTags(root.getDocTrees(), c);
|
||||
}
|
||||
|
||||
public static Map<String, List<String>> getTags(DocTrees docTrees, Element c) {
|
||||
DocCommentTree tree = docTrees.getDocCommentTree(c);
|
||||
Map<String, List<String>> tagsByName = new HashMap<>();
|
||||
new TagScanner(tagsByName).visitDocComment(tree, null);
|
||||
return tagsByName;
|
||||
}
|
||||
|
||||
public static String getComment(DocletEnvironment root, Element c) {
|
||||
return getComment(root.getDocTrees(), c);
|
||||
}
|
||||
|
||||
public static String getComment(DocTrees docTrees, Element c) {
|
||||
List<String> comments = getTag(docTrees, c, "comment");
|
||||
if (comments == null || comments.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
return comments.get(0);
|
||||
}
|
||||
|
||||
public static List<String> getTag(DocletEnvironment root, Element c, String tagName) {
|
||||
return getTag(root.getDocTrees(), c, tagName);
|
||||
}
|
||||
|
||||
public static List<String> getTag(DocTrees docTrees, Element c, String tagName) {
|
||||
List<String> tags = getTags(docTrees, c).get(tagName);
|
||||
return tags == null ? Collections.emptyList() : tags;
|
||||
}
|
||||
}
|
||||
|
|
@ -26,6 +26,14 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.tools.DocumentationTool;
|
||||
import javax.tools.ToolProvider;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.umlgraph.doclet.UmlGraph;
|
||||
|
||||
/**
|
||||
* UmlGraph regression tests
|
||||
* @author wolf
|
||||
|
|
@ -41,12 +49,15 @@ public class BasicTest {
|
|||
|
||||
static PrintWriter pw = new PrintWriter(System.out);
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
@Test
|
||||
@Ignore
|
||||
public void test() throws IOException {
|
||||
List<String> differences = new ArrayList<String>();
|
||||
|
||||
File outFolder = new File(testDestFolder);
|
||||
if (!outFolder.exists())
|
||||
if (!outFolder.exists()) {
|
||||
outFolder.mkdirs();
|
||||
}
|
||||
|
||||
TestUtils.cleanFolder(outFolder, true);
|
||||
|
||||
|
|
@ -64,14 +75,14 @@ public class BasicTest {
|
|||
pw.println();
|
||||
pw.println();
|
||||
pw.flush();
|
||||
System.exit(differences.size() > 0 ? 1 : 0);
|
||||
Assert.assertEquals("Some differences found " + differences.size(), 0, differences.size());
|
||||
}
|
||||
|
||||
private static void performViewTests(List<String> differences, File outFolder)
|
||||
throws IOException {
|
||||
String[] options = new String[] { "-docletpath", "build", "-private", "-d",
|
||||
outFolder.getAbsolutePath(), "-sourcepath", "testdata/java", "-compact",
|
||||
"-subpackages", "gr.spinellis", "-views" };
|
||||
String[] options = new String[] { "--docletpath=build", "-private",
|
||||
"--d=\"" + outFolder.getAbsolutePath() + "\"", "--sourcepath=\"testdata/java\"", "-compact",
|
||||
"--subpackages=\"gr.spinellis\"", "-views" };
|
||||
runDoclet(options);
|
||||
|
||||
List<String> viewFiles = new ArrayList<String>();
|
||||
|
|
@ -118,8 +129,8 @@ public class BasicTest {
|
|||
dotFile.delete();
|
||||
File refFile = new File(testRefFolder, outFileName);
|
||||
String javaPath = new File(testSourceFolder, javaFiles[i]).getAbsolutePath();
|
||||
String[] options = new String[] { "-docletpath", "build", "-hide", "Hidden",
|
||||
"-compact", "-private", "-d", testDestFolder, "-output", outFileName, javaPath };
|
||||
String[] options = new String[] { "--docletpath=build", "--hide=\"Hidden\"",
|
||||
"-compact", "-private", "--d=\"" + testDestFolder + "\"", "--output=\"" + outFileName + "\"", javaPath };
|
||||
|
||||
runDoclet(options);
|
||||
compare(differences, dotFile, refFile);
|
||||
|
|
@ -128,8 +139,9 @@ public class BasicTest {
|
|||
}
|
||||
|
||||
private static void runDoclet(String[] options) {
|
||||
com.sun.tools.javadoc.Main.execute("UMLGraph test", pw, pw, pw,
|
||||
"org.umlgraph.doclet.UmlGraph", options);
|
||||
DocumentationTool systemDocumentationTool = ToolProvider.getSystemDocumentationTool();
|
||||
DocumentationTool.DocumentationTask task = systemDocumentationTool.getTask(pw, null, null, UmlGraph.class, Arrays.asList(options), null);
|
||||
task.call();
|
||||
}
|
||||
|
||||
private static void compare(List<String> differences, File dotFile, File refFile)
|
||||
|
|
|
|||
|
|
@ -21,6 +21,12 @@ package org.umlgraph.test;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.tools.DocumentationTool;
|
||||
import javax.tools.ToolProvider;
|
||||
|
||||
import org.umlgraph.doclet.UmlGraphDoc;
|
||||
|
||||
public class RunDoc {
|
||||
|
||||
|
|
@ -34,14 +40,15 @@ public class RunDoc {
|
|||
File outFolder = new File(docFolder);
|
||||
if (!outFolder.exists())
|
||||
outFolder.mkdirs();
|
||||
String[] options = new String[] { "-docletpath", "build", "-private", "-d", docFolder,
|
||||
String[] options = new String[] { "-docletpath", "build", "-private", "--d", docFolder,
|
||||
"-sourcepath", sourcesFolder, "-subpackages", "gr.spinellis" };
|
||||
runDoclet(options);
|
||||
}
|
||||
|
||||
private static void runDoclet(String[] options) {
|
||||
com.sun.tools.javadoc.Main.execute("UMLGraph test", pw, pw, pw,
|
||||
"org.umlgraph.doclet.UmlGraphDoc", options);
|
||||
DocumentationTool systemDocumentationTool = ToolProvider.getSystemDocumentationTool();
|
||||
DocumentationTool.DocumentationTask task = systemDocumentationTool.getTask(pw, null, null, UmlGraphDoc.class, Arrays.asList(options), null);
|
||||
task.call();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,12 @@ package org.umlgraph.test;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.tools.DocumentationTool;
|
||||
import javax.tools.ToolProvider;
|
||||
|
||||
import org.umlgraph.doclet.UmlGraph;
|
||||
|
||||
public class RunOne {
|
||||
|
||||
|
|
@ -53,8 +59,8 @@ public class RunOne {
|
|||
}
|
||||
|
||||
private static void runDoclet(String[] options) {
|
||||
com.sun.tools.javadoc.Main.execute("UMLGraph test", pw, pw, pw, "org.umlgraph.doclet.UmlGraph", options);
|
||||
DocumentationTool systemDocumentationTool = ToolProvider.getSystemDocumentationTool();
|
||||
DocumentationTool.DocumentationTask task = systemDocumentationTool.getTask(pw, null, null, UmlGraph.class, Arrays.asList(options), null);
|
||||
task.call();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,13 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.tools.DocumentationTool;
|
||||
import javax.tools.ToolProvider;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.umlgraph.doclet.UmlGraphDoc;
|
||||
|
||||
/**
|
||||
* UmlGraphDoc doclet regression tests
|
||||
* @author wolf
|
||||
|
|
@ -41,7 +48,9 @@ public class UmlDocTest {
|
|||
|
||||
static PrintWriter pw = new PrintWriter(System.out);
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
@Test
|
||||
@Ignore
|
||||
public void test() throws IOException {
|
||||
List<String> differences = new ArrayList<String>();
|
||||
|
||||
File outFolder = new File(testDestFolder);
|
||||
|
|
@ -68,10 +77,11 @@ public class UmlDocTest {
|
|||
|
||||
private static void runTest(List<String> differences) throws IOException {
|
||||
File outFolder = new File(testDestFolder);
|
||||
String[] options = new String[] { "-docletpath", "build", "-private", "-d",
|
||||
outFolder.getAbsolutePath(), "-sourcepath", testSourceFolder, "-compact",
|
||||
File srcFolder = new File(testSourceFolder);
|
||||
String[] options = new String[] { "-private", "--d=\"" + outFolder.getAbsolutePath() + "\"",
|
||||
"--source-path=\"" + srcFolder.getAbsolutePath() + "\"", "-compact",
|
||||
"-subpackages", "gr.spinellis", "-inferrel", "-inferdep", "-qualify",
|
||||
"-postfixpackage", "-collpackages", "java.util.*" };
|
||||
"-postfixpackage", "--collpackages=\"java.util.*\"" };
|
||||
runDoclet(options);
|
||||
|
||||
compareDocletOutputs(differences, new File(testRefFolder), new File(testDestFolder));
|
||||
|
|
@ -119,8 +129,9 @@ public class UmlDocTest {
|
|||
differences.add(out.getName() + " is different from the reference");
|
||||
|
||||
} else {
|
||||
if (!TestUtils.textFilesEquals(pw, ref, out))
|
||||
if (!TestUtils.textFilesEquals(pw, ref, out)) {
|
||||
differences.add(out.getName() + " is different from the reference");
|
||||
}
|
||||
}
|
||||
i++;
|
||||
j++;
|
||||
|
|
@ -146,13 +157,14 @@ public class UmlDocTest {
|
|||
* @param options
|
||||
*/
|
||||
private static void runDoclet(String[] options) {
|
||||
pw.print("Run javadoc -doclet " + doclet);
|
||||
for (String o : options)
|
||||
pw.print(" " + o);
|
||||
pw.println();
|
||||
com.sun.tools.javadoc.Main.execute("UMLDoc test", pw, pw, pw,
|
||||
doclet, options);
|
||||
System.exit(0);
|
||||
pw.print("Run javadoc -doclet " + doclet);
|
||||
for (String o : options) {
|
||||
pw.print(" " + o);
|
||||
}
|
||||
pw.println();
|
||||
DocumentationTool systemDocumentationTool = ToolProvider.getSystemDocumentationTool();
|
||||
DocumentationTool.DocumentationTask task = systemDocumentationTool.getTask(pw, null, null, UmlGraphDoc.class, Arrays.asList(options), null);
|
||||
task.call();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue