abstractdoclet.java
来自「linux下建立JAVA虚拟机的源码KAFFE」· Java 代码 · 共 1,370 行 · 第 1/3 页
JAVA
1,370 行
public static final UsageType CLASS_IMPLEMENTING = new UsageType("class-implementing"); public static final UsageType FIELD_OF_TYPE = new UsageType("field-of-type"); public static final UsageType METHOD_WITH_RETURN_TYPE = new UsageType("method-with-return-type"); public static final UsageType METHOD_WITH_PARAMETER_TYPE = new UsageType("method-with-parameter-type"); public static final UsageType METHOD_WITH_THROWN_TYPE = new UsageType("method-with-thrown-type"); public static final UsageType CONSTRUCTOR_WITH_PARAMETER_TYPE = new UsageType("constructor-with-parameter-type"); public static final UsageType CONSTRUCTOR_WITH_THROWN_TYPE = new UsageType("constructor-with-thrown-type"); private String id; private UsageType(String id) { this.id = id; } public int compareTo(Object other) { return this.id.compareTo(((UsageType)other).id); } public String toString() { return "UsageType{id=" + id + "}"; } public String getId() { return id; } } private ResourceBundle resources; protected String getString(String key) { if (null == resources) { Locale currentLocale = Locale.getDefault(); resources = ResourceBundle.getBundle("htmldoclet.HtmlDoclet", currentLocale); } return resources.getString(key); } protected String format(String key, String value1) { return MessageFormat.format(getString(key), new Object[] { value1 }); } protected List getPackageGroups() { return packageGroups; } protected void copyDocFiles(File sourceDir, File targetDir) throws IOException { File sourceDocFiles = new File(sourceDir, "doc-files"); File targetDocFiles = new File(targetDir, "doc-files"); if (sourceDocFiles.exists()) { IOToolkit.copyDirectory(sourceDocFiles, targetDocFiles, optionDocFilesSubDirs.getValue(), optionExcludeDocFilesSubDir.getComponents()); } } private Set sourcePaths; /** * Try to determine the source directory for the given package by * looking at the path specified by -sourcepath, or the current * directory if -sourcepath hasn't been specified. * * @throws IOException if the source directory couldn't be * located. * * @return List of File */ protected List getPackageSourceDirs(PackageDoc packageDoc) throws IOException { if (null == sourcePaths) { for (int i=0; i<rootDoc.options().length; ++i) { if ("-sourcepath".equals(rootDoc.options()[i][0]) || "-s".equals(rootDoc.options()[i][0])) { sourcePaths = new LinkedHashSet(); String sourcepathString = rootDoc.options()[i][1]; StringTokenizer st = new StringTokenizer(sourcepathString, File.pathSeparator); while (st.hasMoreTokens()) { sourcePaths.add(new File(st.nextToken())); } } } if (null == sourcePaths) { sourcePaths = new LinkedHashSet(); sourcePaths.add(new File(System.getProperty("user.dir"))); } } String packageSubDir = packageDoc.name().replace('.', File.separatorChar); Iterator it = sourcePaths.iterator(); List result = new LinkedList(); while (it.hasNext()) { File pathComponent = (File)it.next(); File packageDir = new File(pathComponent, packageSubDir); if (packageDir.exists()) { result.add(packageDir); } } if (result.isEmpty()) { throw new IOException("Couldn't locate source directory for package " + packageDoc.name()); } else { return result; } } protected File getSourceFile(ClassDoc classDoc) throws IOException { List packageDirs = getPackageSourceDirs(classDoc.containingPackage()); Iterator it = packageDirs.iterator(); while (it.hasNext()) { File packageDir = (File)it.next(); File sourceFile = new File(packageDir, getOuterClassDoc(classDoc).name() + ".java"); if (sourceFile.exists()) { return sourceFile; } } throw new IOException("Couldn't locate source file for class " + classDoc.qualifiedTypeName()); } protected void printError(String error) { if (null != rootDoc) { rootDoc.printError(error); } else { System.err.println("ERROR: "+error); } } protected void printWarning(String warning) { if (null != rootDoc) { rootDoc.printWarning(warning); } else { System.err.println("WARNING: "+warning); } } protected void printNotice(String notice) { if (null != rootDoc) { rootDoc.printNotice(notice); } else { System.err.println(notice); } } protected static ClassDoc getOuterClassDoc(ClassDoc classDoc) { while (null != classDoc.containingClass()) { classDoc = classDoc.containingClass(); } return classDoc; } private SortedSet allPackages; protected Set getAllPackages() { if (null == this.allPackages) { allPackages = new TreeSet(); PackageDoc[] specifiedPackages = rootDoc.specifiedPackages(); for (int i=0; i<specifiedPackages.length; ++i) { allPackages.add(specifiedPackages[i]); } ClassDoc[] specifiedClasses = rootDoc.specifiedClasses(); for (int i=0; i<specifiedClasses.length; ++i) { allPackages.add(specifiedClasses[i].containingPackage()); } } return this.allPackages; } protected boolean omitPackageQualifier(PackageDoc packageDoc) { if (!optionNoQualifier.isSpecified()) { return false; } else { return optionNoQualifier.match(packageDoc); } } protected String possiblyQualifiedName(Type type) { if (null == type.asClassDoc() || !omitPackageQualifier(type.asClassDoc().containingPackage())) { return type.qualifiedTypeName(); } else { return type.typeName(); } } protected static class InterfaceRelation { public Set superInterfaces; public Set subInterfaces; public Set implementingClasses; public InterfaceRelation() { superInterfaces = new TreeSet(); subInterfaces = new TreeSet(); implementingClasses = new TreeSet(); } } private void addAllInterfaces(ClassDoc classDoc, Set allInterfaces) { ClassDoc[] interfaces = classDoc.interfaces(); for (int i=0; i<interfaces.length; ++i) { allInterfaces.add(interfaces[i]); addAllInterfaces(interfaces[i], allInterfaces); } } private Map allSubClasses; protected Map getAllSubClasses() { if (null == allSubClasses) { allSubClasses = new HashMap(); ClassDoc[] classDocs = getRootDoc().classes(); for (int i=0; i<classDocs.length; ++i) { if (!classDocs[i].isInterface()) { for (ClassDoc cd = classDocs[i].superclass(); null != cd; cd = cd.superclass()) { if (!cd.qualifiedTypeName().equals("java.lang.Object")) { List subClasses = (List)allSubClasses.get(cd); if (null == subClasses) { subClasses = new LinkedList(); allSubClasses.put(cd, subClasses); } subClasses.add(classDocs[i]); } } } } } return allSubClasses; } private Map interfaceRelations; private void addToInterfaces(ClassDoc classDoc, ClassDoc[] interfaces) { for (int i=0; i<interfaces.length; ++i) { InterfaceRelation interfaceRelation = (InterfaceRelation)interfaceRelations.get(interfaces[i]); if (null == interfaceRelation) { interfaceRelation = new InterfaceRelation(); interfaceRelations.put(interfaces[i], interfaceRelation); } interfaceRelation.implementingClasses.add(classDoc); addToInterfaces(classDoc, interfaces[i].interfaces()); } } protected Map getInterfaceRelations() { if (null == interfaceRelations) { interfaceRelations = new HashMap(); ClassDoc[] classDocs = getRootDoc().classes(); for (int i=0; i<classDocs.length; ++i) { if (classDocs[i].isInterface()) { InterfaceRelation relation = new InterfaceRelation(); addAllInterfaces(classDocs[i], relation.superInterfaces); interfaceRelations.put(classDocs[i], relation); } } Iterator it = interfaceRelations.keySet().iterator(); while (it.hasNext()) { ClassDoc interfaceDoc = (ClassDoc)it.next(); InterfaceRelation relation = (InterfaceRelation)interfaceRelations.get(interfaceDoc); Iterator superIt = relation.superInterfaces.iterator(); while (superIt.hasNext()) { ClassDoc superInterfaceDoc = (ClassDoc)superIt.next(); InterfaceRelation superRelation = (InterfaceRelation)interfaceRelations.get(superInterfaceDoc); if (null != superRelation) { superRelation.subInterfaces.add(interfaceDoc); } } } for (int i=0; i<classDocs.length; ++i) { if (!classDocs[i].isInterface()) { for (ClassDoc cd = classDocs[i]; null != cd; cd = cd.superclass()) { addToInterfaces(classDocs[i], cd.interfaces()); } } } } return interfaceRelations; } private Map sortedMethodMap = new HashMap(); protected MethodDoc[] getSortedMethods(ClassDoc classDoc) { MethodDoc[] result = (MethodDoc[])sortedMethodMap.get(classDoc); if (null == result) { MethodDoc[] methods = classDoc.methods(); result = (MethodDoc[])methods.clone(); Arrays.sort(result); return result; } return result; } private Map sortedConstructorMap = new HashMap(); protected ConstructorDoc[] getSortedConstructors(ClassDoc classDoc) { ConstructorDoc[] result = (ConstructorDoc[])sortedConstructorMap.get(classDoc); if (null == result) { ConstructorDoc[] constructors = classDoc.constructors(); result = (ConstructorDoc[])constructors.clone(); Arrays.sort(result); return result; } return result; } private Map sortedFieldMap = new HashMap(); protected FieldDoc[] getSortedFields(ClassDoc classDoc) { FieldDoc[] result = (FieldDoc[])sortedFieldMap.get(classDoc); if (null == result) { FieldDoc[] fields = classDoc.fields(); result = (FieldDoc[])fields.clone(); Arrays.sort(result); return result; } return result; } private Map sortedInnerClassMap = new HashMap(); protected ClassDoc[] getSortedInnerClasses(ClassDoc classDoc) { ClassDoc[] result = (ClassDoc[])sortedInnerClassMap.get(classDoc); if (null == result) { ClassDoc[] innerClasses = classDoc.innerClasses(); result = (ClassDoc[])innerClasses.clone(); Arrays.sort(result); return result; } return result; } protected abstract String renderTag(String tagName, Tag[] tags, TagletContext context); protected abstract String getDocletVersion(); protected SortedSet getThrownExceptions(ExecutableMemberDoc execMemberDoc) { SortedSet result = new TreeSet(); ClassDoc[] thrownExceptions = execMemberDoc.thrownExceptions(); for (int j=0; j<thrownExceptions.length; ++j) { result.add(thrownExceptions[j]); } return result; } protected boolean isUncheckedException(ClassDoc classDoc) { if (classDoc.isException()) { while (null != classDoc) { if (classDoc.qualifiedTypeName().equals("java.lang.RuntimeException")) { return true; } classDoc = classDoc.superclass(); } return false; } else { return false; } } protected FieldDoc findField(ClassDoc classDoc, String fieldName) { for (ClassDoc cd = classDoc; cd != null; cd = cd.superclass()) { FieldDoc[] fields = cd.fields(false); for (int i=0; i<fields.length; ++i) { if (fields[i].name().equals(fieldName)) { return fields[i]; } } } return null; } private Map implementedInterfacesCache = new HashMap(); protected Set getImplementedInterfaces(ClassDoc classDoc) { Set result = (Set)implementedInterfacesCache.get(classDoc); if (null == result) { result = new TreeSet(); for (ClassDoc cd = classDoc; cd != null; cd = cd.superclass()) { ClassDoc[] interfaces = cd.interfaces(); for (int i=0; i<interfaces.length; ++i) { result.add(interfaces[i]); InterfaceRelation relation = (InterfaceRelation)getInterfaceRelations().get(interfaces[i]); if (null != relation) { result.addAll(relation.superInterfaces); } } } implementedInterfacesCache.put(classDoc, result); } return result; } protected boolean isSinglePackage() { return getAllPackages().size() <= 1; } protected PackageDoc getSinglePackage() { return (PackageDoc)getAllPackages().iterator().next(); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?