📄 docimpl.java
字号:
AbstractTagImpl tag = null; boolean haveValue = (0 != value.trim().length()); String emptyWarning = "Empty @" + name + " tag."; if (name.equals("param")) { if (haveValue) { tag=new ParamTagImpl(value, contextClass, contextMember); } else { //printWarning(emptyWarning); } } else if (name.equals("see")) { if (haveValue) { tag=new SeeTagImpl(value, contextClass); } else { //printWarning(emptyWarning); } } else if (name.equals("link") || name.equals("linkplain")) { if (haveValue) { tag=new LinkTagImpl("@" + name, value, contextClass); isInline = true; } else { //printWarning(emptyWarning); } } else if (name.equals("value")) { if (haveValue) { tag=new ValueTagImpl(value, contextClass); isInline = true; } else { //printWarning(emptyWarning); } } else if (name.equals("inheritDoc")) { if (haveValue) { //printWarning("@inheritDoc tags are not supposed to have any content."); } tag=new InheritDocTagImpl(contextClass, contextMember, contextTag); isInline = true; } else if (name.equals("serialField")) { if (haveValue) { tag=new SerialFieldTagImpl(value, contextClass, contextMember); } else { //printWarning(emptyWarning); } } else if (name.equals("throws") || name.equals("exception")) { if (haveValue) { tag=new ThrowsTagImpl(value, contextClass, contextMember); } else { //printWarning(emptyWarning); } name="throws"; } else if (name.equals("text")) { tag=new TextTagImpl(value); isInline = true; } else { tag=new TagImpl("@"+name, value.trim(), contextClass, contextMember); // FIXME: consider taglets } if (tag != null) { if (isInline) { ((List)tags.get("inline")).add(tag); if (isFirstSentence) { if (name.equals("text")) { String txt = ((TextTagImpl)tag).getText(); Tag newTag; if (txt.startsWith("<p>")) { newTag = new TextTagImpl(txt.substring(3)); } else if (txt.endsWith("</p>")) { newTag = new TextTagImpl(txt.substring(0, txt.length() - 4)); } else { newTag = tag; } ((List)tags.get("first")).add(newTag); } else { ((List)tags.get("first")).add(tag); } } } else { ((List)tags.get("all")).add(tag); } List l=((List)tags.get(name)); if (l==null) { l=new LinkedList(); tags.put(name,l); } l.add(tag); return isInline ? tag : contextTag; } else { return null; } } // Return all tags in this Doc item. public Tag[] tags() { Tag[] rc=(Tag[])tagMap.get("all"); if (rc==null) rc=new Tag[0]; return rc; } // Return tags of the specified kind in this Doc item. public Tag[] tags(java.lang.String tagname) { Tag[] rc=(Tag[])tagMap.get(tagname); if (rc==null) rc=new Tag[0]; return rc; } protected String rawDocumentation; protected long rawDocOffset=-1; protected Map tagMap = new HashMap(); public Map getTagMap() { return tagMap; } protected void resolveTags() { Tag[] tags=tags(); for (int i=0; i<tags.length; ++i) { ((AbstractTagImpl)tags[i]).resolve(); } Tag[] inlineTags=inlineTags(); for (int i=0; i<inlineTags.length; ++i) { ((AbstractTagImpl)inlineTags[i]).resolve(); } } private static Map classDocToFileMap = new HashMap(); private static File getFile(ClassDoc classDoc) { File result = (File)classDocToFileMap.get(classDoc); if (null == result) { result = new File(((GjdocPackageDoc)classDoc.containingPackage()).packageDirectory(), classDoc.name() + ".java"); classDocToFileMap.put(classDoc, result); } return result; } public static SourcePosition getPosition(ClassDoc classDoc) { return new SourcePositionImpl(getFile(classDoc), 0, 0); } public static SourcePosition getPosition(ClassDoc classDoc, char[] source, int startIndex) { int column = 0; int line = 0; for (int i=0; i<startIndex; ++i) { if (10 == source[i]) { ++ line; column = 0; } else if (13 != source[i]) { ++ column; } } while (true) { ClassDoc containingClassDoc = classDoc.containingClass(); if (null != containingClassDoc) { classDoc = containingClassDoc; } else { break; } } File file = getFile(classDoc); return new SourcePositionImpl(file, line + 1, column + 1); } public SourcePosition position() { return this.position; } public DocImpl(SourcePosition position) { this.position = position; } public void setPosition(SourcePosition position) { this.position = position; } private static TagContainer checkForInheritedDoc(ClassDoc classDoc, MemberDocImpl memberDoc, AbstractTagImpl tag) { DocImpl result; if (!(classDoc instanceof ClassDocImpl)) { result = null; } else if (null == memberDoc) { result = (DocImpl)classDoc; } else if (memberDoc.isField()) { result = (DocImpl)((ClassDocImpl)classDoc).getFieldDoc(memberDoc.name()); } else if (memberDoc.isMethod()) { result = (DocImpl)((ClassDocImpl)classDoc).getMethodDoc(memberDoc.name(), ((MethodDoc)memberDoc).signature()); } else if (memberDoc.isConstructor()) { result = (DocImpl)((ClassDocImpl)classDoc).getConstructorDoc(((ConstructorDoc)memberDoc).signature()); } else { //assert(false); throw new RuntimeException("memberDoc is supposed to be field, method or constructor"); } if (null != result && null != memberDoc && null != tag) { TagContainer tagDoc = null; Tag[] tags = result.tags(); for (int i=0; i<tags.length; ++i) { if (tags[i].kind().equals(tag.kind())) { if ("@param".equals(tag.kind())) { if (((ParamTagImpl)tags[i]).parameterName().equals(((ParamTagImpl)tag).parameterName())) { tagDoc = (TagContainer)tags[i]; break; } } else if ("@throws".equals(tag.kind())) { if (((ThrowsTagImpl)tags[i]).exceptionName().equals(((ThrowsTagImpl)tag).exceptionName())) { tagDoc = (TagContainer)tags[i]; break; } } else if ("@return".equals(tag.kind())) { tagDoc = (TagContainer)tags[i]; } } } return tagDoc; } if (null == result || result.isEmptyDoc()) { return null; } else { return result; } } public static TagContainer findInheritedDoc(ClassDoc classDoc, MemberDocImpl memberDoc, AbstractTagImpl tag) { TagContainer result; // (Taken from Javadoc Solaris Tool documentation 1.5, // section "Automatic Copying of Method Comments") // Algorithm for Inheriting Method Comments - If a method does // not have a doc comment, or has an {@inheritDoc} tag, the // Javadoc tool searches for an applicable comment using the // following algorithm, which is designed to find the most // specific applicable doc comment, giving preference to // interfaces over superclasses: // 1. Look in each directly implemented (or extended) interface // in the order they appear following the word implements (or // extends) in the method declaration. Use the first doc comment // found for this method. ClassDoc[] interfaces = classDoc.interfaces(); if (null != interfaces) { for (int i=0; i<interfaces.length; ++i) { result = checkForInheritedDoc(interfaces[i], memberDoc, tag); if (null != result) { return result; } } } // 2. If step 1 failed to find a doc comment, recursively apply // this entire algorithm to each directly implemented (or // extended) interface, in the same order they were examined // in step 1. if (null != interfaces) { for (int i=0; i<interfaces.length; ++i) { result = findInheritedDoc(interfaces[i], memberDoc, tag); if (null != result) { return result; } } } ClassDoc superclassDoc = classDoc.superclass(); // 3. If step 2 failed to find a doc comment and this is a class // other than Object (not an interface): if (!classDoc.isInterface() && null != superclassDoc && !"java.lang.Object".equals(classDoc.qualifiedTypeName())) { // 3a. If the superclass has a doc comment for this method, use it. result = checkForInheritedDoc(superclassDoc, memberDoc, tag); if (null != result) { return result; } // 3b. If step 3a failed to find a doc comment, recursively // apply this entire algorithm to the superclass. return findInheritedDoc(superclassDoc, memberDoc, tag); } else { return null; } } public boolean isEmptyDoc() { return tagMap.isEmpty(); } void setBoilerplateComment(String boilerplateComment) { this.boilerplateComment = boilerplateComment; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -