35 |
import java.util.Arrays; |
import java.util.Arrays; |
36 |
import java.util.Comparator; |
import java.util.Comparator; |
37 |
import java.util.HashSet; |
import java.util.HashSet; |
38 |
|
import java.util.TreeSet; |
39 |
import java.util.Iterator; |
import java.util.Iterator; |
40 |
import java.util.LinkedHashMap; |
import java.util.LinkedHashMap; |
41 |
import java.util.List; |
import java.util.List; |
42 |
import java.util.Locale; |
import java.util.Locale; |
43 |
import java.util.Map; |
import java.util.Map; |
44 |
|
import java.util.HashMap; |
45 |
import java.util.Properties; |
import java.util.Properties; |
46 |
import java.util.Set; |
import java.util.Set; |
47 |
import java.util.StringTokenizer; |
import java.util.StringTokenizer; |
377 |
if (classDoc.isInterface()) { |
if (classDoc.isInterface()) { |
378 |
printAtomTag(2, "isInterface"); |
printAtomTag(2, "isInterface"); |
379 |
} |
} |
380 |
|
if (classDoc.isOrdinaryClass()) { |
381 |
|
printAtomTag(2, "isOrdinaryClass"); |
382 |
|
} |
383 |
|
|
384 |
printCloseTag(1, "classdoc"); |
printCloseTag(1, "classdoc"); |
385 |
} |
} |
391 |
printOpenTag(2, "firstSentenceTags", false); |
printOpenTag(2, "firstSentenceTags", false); |
392 |
outputTags(3, packageDoc.firstSentenceTags(), true, CONTEXT_PACKAGE); |
outputTags(3, packageDoc.firstSentenceTags(), true, CONTEXT_PACKAGE); |
393 |
printCloseTag(0, "firstSentenceTags"); |
printCloseTag(0, "firstSentenceTags"); |
394 |
|
printOpenTag(2, "inlineTags", false); |
395 |
|
outputTags(3, packageDoc.inlineTags(), true, CONTEXT_PACKAGE); |
396 |
|
printCloseTag(0, "inlineTags"); |
397 |
} |
} |
398 |
|
|
399 |
if (packageDoc.tags().length > 0) { |
if (packageDoc.tags().length > 0) { |
427 |
println(); |
println(); |
428 |
printOpenTag(1, "classdoc xmlns=\"http://www.w3.org/TR/REC-html40\" xmlns:"+tagPrefix+"=\"http://www.gnu.org/software/cp-tools/gjdocxml\" name=\""+classDoc.name()+"\" qualifiedtypename=\""+classDoc.qualifiedName()+"\""); |
printOpenTag(1, "classdoc xmlns=\"http://www.w3.org/TR/REC-html40\" xmlns:"+tagPrefix+"=\"http://www.gnu.org/software/cp-tools/gjdocxml\" name=\""+classDoc.name()+"\" qualifiedtypename=\""+classDoc.qualifiedName()+"\""); |
429 |
|
|
|
if (null!=classDoc.superclass()) { |
|
|
outputType(2, "superclass", classDoc.superclass()); |
|
|
} |
|
|
|
|
430 |
ClassDoc[] interfaces = classDoc.interfaces(); |
ClassDoc[] interfaces = classDoc.interfaces(); |
431 |
for (int i=0, ilim=interfaces.length; i<ilim; ++i) { |
for (int i=0, ilim=interfaces.length; i<ilim; ++i) { |
432 |
outputType(2, "implements", interfaces[i]); |
outputType(2, "implements", interfaces[i]); |
474 |
print(java2xhtml.makeHTML(sourceBuffer.getBuffer(), sourceFile.getName())); |
print(java2xhtml.makeHTML(sourceBuffer.getBuffer(), sourceFile.getName())); |
475 |
printCloseTag(2, "source"); |
printCloseTag(2, "source"); |
476 |
} |
} |
477 |
|
|
478 |
|
ClassDoc superclassDoc = classDoc.superclass(); |
479 |
|
while (superclassDoc != null) { |
480 |
|
printOpenTag(2, "superclass typename=\"" + superclassDoc.typeName() + "\" qualifiedtypename=\"" + superclassDoc.qualifiedTypeName() + "\""); |
481 |
|
|
482 |
|
printAtomTag(3, "containingPackage name=\"" + superclassDoc.containingPackage().name() + "\""); |
483 |
|
|
484 |
|
MethodDoc[] superMethods = superclassDoc.methods(); |
485 |
|
for (int i=0, ilim=superMethods.length; i<ilim; ++i) { |
486 |
|
printAtomTag(3, "methoddoc name=\"" + superMethods[i].name() + "\" signature=\"" + superMethods[i].signature() + "\""); |
487 |
|
} |
488 |
|
|
489 |
|
FieldDoc[] superFields = superclassDoc.fields(); |
490 |
|
for (int i=0, ilim=superFields.length; i<ilim; ++i) { |
491 |
|
printAtomTag(3, "fielddoc name=\"" + superFields[i].name() + "\""); |
492 |
|
} |
493 |
|
printCloseTag(2, "superclass"); |
494 |
|
|
495 |
|
superclassDoc = superclassDoc.superclass(); |
496 |
|
} |
497 |
|
|
498 |
|
outputUsage(classDoc, 2); |
499 |
|
|
500 |
printCloseTag(1, "classdoc"); |
printCloseTag(1, "classdoc"); |
501 |
|
|
502 |
currentClass = null; |
currentClass = null; |
1021 |
else if ("-nodeprecatedlist".equals(optionTag)) { |
else if ("-nodeprecatedlist".equals(optionTag)) { |
1022 |
docTransletOptions.nodeprecatedlist = true; |
docTransletOptions.nodeprecatedlist = true; |
1023 |
} |
} |
1024 |
|
else if ("-uses".equals(optionTag)) { |
1025 |
|
docTransletOptions.uses = true; |
1026 |
|
} |
1027 |
else if ("-tag".equals(optionTag)) { |
else if ("-tag".equals(optionTag)) { |
1028 |
String tagSpec = option[1]; |
String tagSpec = option[1]; |
1029 |
boolean validTagSpec = false; |
boolean validTagSpec = false; |
1239 |
} |
} |
1240 |
} |
} |
1241 |
|
|
1242 |
|
collectUsage(); |
1243 |
|
|
1244 |
// Begin XML generation |
// Begin XML generation |
1245 |
|
|
1246 |
printNotice("Writing XML Index file..."); |
printNotice("Writing XML Index file..."); |
1668 |
else if ("-bottom".equals(option)) return 2; |
else if ("-bottom".equals(option)) return 2; |
1669 |
else if ("-doctitle".equals(option)) return 2; |
else if ("-doctitle".equals(option)) return 2; |
1670 |
else if ("-nodeprecatedlist".equals(option)) return 1; |
else if ("-nodeprecatedlist".equals(option)) return 1; |
1671 |
|
else if ("-uses".equals(option)) return 1; |
1672 |
|
|
1673 |
else return -1; |
else return -1; |
1674 |
} |
} |
2033 |
out.write(buf, 0, nread); |
out.write(buf, 0, nread); |
2034 |
} |
} |
2035 |
} |
} |
2036 |
|
|
2037 |
|
private static class UsageType |
2038 |
|
{ |
2039 |
|
public static final UsageType CLASS_DERIVED_FROM = new UsageType("class-derived-from"); |
2040 |
|
public static final UsageType FIELD_OF_TYPE = new UsageType("field-of-type"); |
2041 |
|
public static final UsageType METHOD_WITH_RETURN_TYPE = new UsageType("method-with-return-type"); |
2042 |
|
public static final UsageType METHOD_WITH_PARAMETER_TYPE = new UsageType("method-with-parameter-type"); |
2043 |
|
public static final UsageType METHOD_WITH_THROWN_TYPE = new UsageType("method-with-thrown-type"); |
2044 |
|
public static final UsageType CONSTRUCTOR_WITH_PARAMETER_TYPE = new UsageType("constructor-with-parameter-type"); |
2045 |
|
public static final UsageType CONSTRUCTOR_WITH_THROWN_TYPE = new UsageType("constructor-with-thrown-type"); |
2046 |
|
private String id; |
2047 |
|
|
2048 |
|
private UsageType(String id) |
2049 |
|
{ |
2050 |
|
this.id = id; |
2051 |
|
} |
2052 |
|
|
2053 |
|
public String toString() { |
2054 |
|
return "UsageType{id=" + id + "}"; |
2055 |
|
} |
2056 |
|
|
2057 |
|
public String getId() { |
2058 |
|
return id; |
2059 |
|
} |
2060 |
|
} |
2061 |
|
|
2062 |
|
/** |
2063 |
|
* ClassDoc -> (PackageDoc -> (UsageType -> (Set of Doc))) |
2064 |
|
*/ |
2065 |
|
private Map usedClassToPackagesMap = new HashMap(); |
2066 |
|
|
2067 |
|
private void addUsedBy(ClassDoc usedClass, UsageType usageType, Doc user, PackageDoc userPackage) |
2068 |
|
{ |
2069 |
|
Map packageToUsageTypeMap = (Map)usedClassToPackagesMap.get(usedClass); |
2070 |
|
if (null == packageToUsageTypeMap) { |
2071 |
|
packageToUsageTypeMap = new HashMap(); |
2072 |
|
usedClassToPackagesMap.put(usedClass, packageToUsageTypeMap); |
2073 |
|
} |
2074 |
|
|
2075 |
|
Map usageTypeToUsersMap = (Map)packageToUsageTypeMap.get(userPackage); |
2076 |
|
if (null == usageTypeToUsersMap) { |
2077 |
|
usageTypeToUsersMap = new HashMap(); |
2078 |
|
packageToUsageTypeMap.put(userPackage, usageTypeToUsersMap); |
2079 |
|
} |
2080 |
|
|
2081 |
|
Set userSet = (Set)usageTypeToUsersMap.get(usageType); |
2082 |
|
if (null == userSet) { |
2083 |
|
userSet = new TreeSet(); // FIXME: we need the collator from Main here |
2084 |
|
usageTypeToUsersMap.put(usageType, userSet); |
2085 |
|
} |
2086 |
|
userSet.add(user); |
2087 |
|
} |
2088 |
|
|
2089 |
|
/** |
2090 |
|
* Create the cross reference database. |
2091 |
|
*/ |
2092 |
|
private void collectUsage() { |
2093 |
|
|
2094 |
|
ClassDoc[] classes = rootDoc.classes(); |
2095 |
|
for (int i = 0, ilim = classes.length; i < ilim; ++ i) { |
2096 |
|
ClassDoc clazz = classes[i]; |
2097 |
|
|
2098 |
|
// classes derived from |
2099 |
|
for (ClassDoc superclass = clazz.superclass(); superclass != null; |
2100 |
|
superclass = superclass.superclass()) { |
2101 |
|
addUsedBy(superclass, UsageType.CLASS_DERIVED_FROM, clazz, clazz.containingPackage()); |
2102 |
|
} |
2103 |
|
|
2104 |
|
FieldDoc[] fields = clazz.fields(); |
2105 |
|
for (int j = 0, jlim = fields.length; j < jlim; ++ j) { |
2106 |
|
FieldDoc field = fields[j]; |
2107 |
|
|
2108 |
|
// fields of type |
2109 |
|
ClassDoc fieldType = field.type().asClassDoc(); |
2110 |
|
if (null != fieldType) { |
2111 |
|
addUsedBy(fieldType, UsageType.FIELD_OF_TYPE, |
2112 |
|
field, clazz.containingPackage()); |
2113 |
|
} |
2114 |
|
} |
2115 |
|
|
2116 |
|
MethodDoc[] methods = clazz.methods(); |
2117 |
|
for (int j = 0, jlim = methods.length; j < jlim; ++ j) { |
2118 |
|
MethodDoc method = methods[j]; |
2119 |
|
|
2120 |
|
// methods with return type |
2121 |
|
|
2122 |
|
ClassDoc returnType = method.returnType().asClassDoc(); |
2123 |
|
if (null != returnType) { |
2124 |
|
addUsedBy(returnType, UsageType.METHOD_WITH_RETURN_TYPE, |
2125 |
|
method, clazz.containingPackage()); |
2126 |
|
} |
2127 |
|
Parameter[] parameters = method.parameters(); |
2128 |
|
for (int k=0; k<parameters.length; ++k) { |
2129 |
|
|
2130 |
|
// methods with parameter type |
2131 |
|
|
2132 |
|
Parameter parameter = parameters[k]; |
2133 |
|
ClassDoc parameterType = parameter.type().asClassDoc(); |
2134 |
|
if (null != parameterType) { |
2135 |
|
addUsedBy(parameterType, UsageType.METHOD_WITH_PARAMETER_TYPE, |
2136 |
|
method, clazz.containingPackage()); |
2137 |
|
} |
2138 |
|
} |
2139 |
|
|
2140 |
|
// methods which throw |
2141 |
|
|
2142 |
|
ClassDoc[] thrownExceptions = method.thrownExceptions(); |
2143 |
|
for (int k = 0, klim = thrownExceptions.length; k < klim; ++ k) { |
2144 |
|
ClassDoc thrownException = thrownExceptions[k]; |
2145 |
|
addUsedBy(thrownException, UsageType.METHOD_WITH_THROWN_TYPE, |
2146 |
|
method, clazz.containingPackage()); |
2147 |
|
} |
2148 |
|
} |
2149 |
|
|
2150 |
|
ConstructorDoc[] constructors = clazz.constructors(); |
2151 |
|
for (int j = 0, jlim = constructors.length; j < jlim; ++ j) { |
2152 |
|
|
2153 |
|
ConstructorDoc constructor = constructors[j]; |
2154 |
|
|
2155 |
|
Parameter[] parameters = constructor.parameters(); |
2156 |
|
for (int k = 0, klim = parameters.length; k < klim; ++ k) { |
2157 |
|
|
2158 |
|
// constructors with parameter type |
2159 |
|
|
2160 |
|
Parameter parameter = parameters[k]; |
2161 |
|
ClassDoc parameterType = parameter.type().asClassDoc(); |
2162 |
|
if (null != parameterType) { |
2163 |
|
addUsedBy(parameterType, UsageType.CONSTRUCTOR_WITH_PARAMETER_TYPE, |
2164 |
|
constructor, clazz.containingPackage()); |
2165 |
|
} |
2166 |
|
} |
2167 |
|
|
2168 |
|
// constructors which throw |
2169 |
|
|
2170 |
|
ClassDoc[] thrownExceptions = constructor.thrownExceptions(); |
2171 |
|
for (int k = 0, klim = thrownExceptions.length; k < klim; ++ k) { |
2172 |
|
ClassDoc thrownException = thrownExceptions[k]; |
2173 |
|
addUsedBy(thrownException, UsageType.CONSTRUCTOR_WITH_THROWN_TYPE, |
2174 |
|
constructor, clazz.containingPackage()); |
2175 |
|
} |
2176 |
|
} |
2177 |
|
} |
2178 |
|
} |
2179 |
|
|
2180 |
|
private void outputUsage(ClassDoc clazz, int level) { |
2181 |
|
|
2182 |
|
Map packageToUsageTypeMap = (Map)usedClassToPackagesMap.get(clazz); |
2183 |
|
if (null != packageToUsageTypeMap) { |
2184 |
|
printOpenTag(level, "references"); |
2185 |
|
|
2186 |
|
Iterator packagesIterator = packageToUsageTypeMap.keySet().iterator(); |
2187 |
|
|
2188 |
|
while (packagesIterator.hasNext()) { |
2189 |
|
PackageDoc packageDoc = (PackageDoc)packagesIterator.next(); |
2190 |
|
printOpenTag(level + 1, "referencing-package name=\"" + packageDoc.name() + "\""); |
2191 |
|
Map usageTypeToUsersMap = (Map)packageToUsageTypeMap.get(packageDoc); |
2192 |
|
Iterator usageTypeIterator = usageTypeToUsersMap.keySet().iterator(); |
2193 |
|
while (usageTypeIterator.hasNext()) { |
2194 |
|
UsageType usageType = (UsageType)usageTypeIterator.next(); |
2195 |
|
printOpenTag(level + 2, "usage-type id=\"" + usageType.getId() + "\""); |
2196 |
|
Set users = (Set)usageTypeToUsersMap.get(usageType); |
2197 |
|
Iterator userIterator = users.iterator(); |
2198 |
|
while (userIterator.hasNext()) { |
2199 |
|
Doc user = (Doc)userIterator.next(); |
2200 |
|
if (user instanceof ClassDoc) { |
2201 |
|
printAtomTag(level + 3, "user" |
2202 |
|
+ " class=\"" + ((ClassDoc)user).name() + "\""); |
2203 |
|
} |
2204 |
|
else if (user instanceof FieldDoc) { |
2205 |
|
FieldDoc fieldDoc = (FieldDoc)user; |
2206 |
|
printAtomTag(level + 3, "user" |
2207 |
|
+ " class=\"" + fieldDoc.containingClass().name() + "\"" |
2208 |
|
+ " field=\"" + fieldDoc.name() + "\""); |
2209 |
|
} |
2210 |
|
else if (user instanceof MethodDoc) { |
2211 |
|
MethodDoc methodDoc = (MethodDoc)user; |
2212 |
|
printAtomTag(level + 3, "user" |
2213 |
|
+ " class=\"" + methodDoc.containingClass().name() + "\"" |
2214 |
|
+ " method=\"" + methodDoc.name() + "\"" |
2215 |
|
+ " signature=\"" + methodDoc.signature() + "\"" |
2216 |
|
+ " flatSignature=\"" + methodDoc.flatSignature() + "\""); |
2217 |
|
} |
2218 |
|
else if (user instanceof ConstructorDoc) { |
2219 |
|
ConstructorDoc constructorDoc = (ConstructorDoc)user; |
2220 |
|
printAtomTag(level + 3, "user" |
2221 |
|
+ " class=\"" + constructorDoc.containingClass().name() + "\"" |
2222 |
|
+ " signature=\"" + constructorDoc.signature() + "\"" |
2223 |
|
+ " flatSignature=\"" + constructorDoc.flatSignature() + "\""); |
2224 |
|
} |
2225 |
|
} |
2226 |
|
printCloseTag(level +2, "usage-type"); |
2227 |
|
} |
2228 |
|
printCloseTag(level + 1, "referencing-package"); |
2229 |
|
} |
2230 |
|
|
2231 |
|
printCloseTag(level, "references"); |
2232 |
|
} |
2233 |
|
} |
2234 |
} |
} |