📄 docimpl.java
字号:
/* gnu.classpath.tools.gjdoc.DocImpl Copyright (C) 2001 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version. GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING. If not, write to theFree Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307 USA. */package gnu.classpath.tools.gjdoc;import com.sun.javadoc.*;import java.util.*;import java.text.*;import java.io.File;import javax.swing.text.Segment;/** * Represents the least common denominator of all Javadoc * comment classes. */public abstract class DocImpl implements Doc, TagContainer { protected static Tag[] seeTagEmptyArr = new SeeTagImpl[0]; protected static Tag[] linkTagEmptyArr = new LinkTagImpl[0]; protected static Tag[] paramTagEmptyArr = new ParamTagImpl[0]; protected static Tag[] throwsTagEmptyArr = new ThrowsTagImpl[0]; protected SourcePosition position; private String boilerplateComment; // Return the text of the comment for this doc item. public String commentText() { StringBuffer rc=new StringBuffer(); Tag[] textTags=(Tag[])tagMap.get("text"); if (textTags!=null) { for (int i=0; i<textTags.length; ++i) { rc.append(textTags[i].text()); } } return rc.toString(); } // Compares this Object with the specified Object for order. public int compareTo(java.lang.Object o) { return Main.getInstance().getCollator().compare(name(), ((Doc)o).name()); } // Return the first sentence of the comment as tags. public Tag[] firstSentenceTags() { Tag[] rc=(Tag[])tagMap.get("first"); if (rc==null) rc=new Tag[0]; return rc; } // Return the full unprocessed text of the comment. public String getRawCommentText() { if (rawDocumentation!=null) return rawDocumentation; else if (rawDocOffset>=0) return Main.getRootDoc().readRawComment(rawDocOffset); else return null; } // Return comment as tags. public Tag[] inlineTags() { Tag[] rc=(Tag[])tagMap.get("inline"); if (rc==null) rc=new Tag[0]; return rc; } // Is this Doc item a class. public boolean isClass() { return false; } // Is this Doc item a constructor? False until overridden. public boolean isConstructor() { return false; } // Is this Doc item a error class? False until overridden. public boolean isError() { return false; } // Is this Doc item a exception class? False until overridden. public boolean isException() { return false; } // Is this Doc item a field? False until overridden. public boolean isField() { return false; } // return true if this Doc is include in the active set. public boolean isIncluded() { return false; } // Is this Doc item a interface? False until overridden. public boolean isInterface() { return false; } // Is this Doc item a simple method (i.e. public boolean isMethod() { return false; } public boolean isPackage() { return false; } // Is this Doc item a ordinary class (i.e. public boolean isOrdinaryClass() { return false; } // Return the see also tags in this Doc item. public SeeTag[] seeTags() { return (SeeTag[])getTagArr("see", seeTagEmptyArr); } protected Tag[] getTagArr(String kindOfTag, Tag[] defaultRc) { Tag[] rc=(Tag[])tagMap.get(kindOfTag); if (rc==null) rc=defaultRc; return rc; } // Set the full unprocessed text of the comment. public void setRawCommentText(String rawDocumentation) { this.rawDocumentation=rawDocumentation; } public void resolveComments() { if (rawDocumentation!=null && tagMap.isEmpty()) { char[] charArray = rawDocumentation.toCharArray(); int length = rawDocumentation.length(); int startOffset = 0; int endOffset = 0; if (charArray[0] == '/' && charArray[1] == '*' && charArray[2] == '*' && charArray[length - 2] == '*' && charArray[length - 1] == '/') { startOffset = 3; endOffset = 2; } this.tagMap=parseCommentTags(charArray, startOffset, length - endOffset, getContextClass(), getContextMember(), null, boilerplateComment); if (Main.getInstance().isCacheRawComments()) { rawDocOffset=Main.getRootDoc().writeRawComment(rawDocumentation); rawDocumentation=null; } resolveTags(); } else if (tagMap.isEmpty() && null != boilerplateComment) { tagMap.put("all", new Tag[] { new TagImpl("@boilerplate", boilerplateComment,getContextClass(),null) }); tagMap.put("@boilerplate", new Tag[] { new TagImpl("@boilerplate", boilerplateComment,getContextClass(),null) }); } } public static int skipHtmlWhitespace(char[] buffer, int startIndex) { while (startIndex < buffer.length) { char c=buffer[startIndex]; if (!Parser.isWhitespace(c)) { break; } else { ++ startIndex; } } return startIndex; } /** * Looks for an end-of-sentence marker in <code>text</code>, * starting at <code>startIndex</code> and stopping at * <code>endIndex</code>. * * @param text the text to be searched * @param startIndex index in <code>text</code> at which to start * @param endIndex index in <code>text</code> at which to stop * * @return the index of the character following the end-of-sentence * marker, <code>endIndex</code> if no end-of-sentence * marker could be found, or -1 if not implemented. */ private static int findEndOfSentence(char[] text, int startIndex, int endIndex) { if (Main.getInstance().isUseBreakIterator()) { Segment segment = new Segment(text, startIndex, endIndex - startIndex); BreakIterator breakIterator = BreakIterator.getSentenceInstance(Main.getInstance().getLocale()); breakIterator.setText(segment); int result = breakIterator.next(); if (BreakIterator.DONE == result) { return endIndex; } else { return result; } } else { while (startIndex < endIndex) { if (text[startIndex] == '.' && (startIndex+1 == endIndex || Character.isWhitespace(text[startIndex+1]) || isHTMLBreakTag(text, startIndex+1, endIndex) )) { return startIndex; } startIndex++; } return endIndex; } } /** * Returns true is the text from start to end begins with a 'p' or 'br' tag. */ private static boolean isHTMLBreakTag(char[] text, int start, int end) { String[] breakTags = { "p>", "/p>", "h1>", "h2>", "h3>", "h4>", "h5>", "h6>", "hr>", "pre>", "/pre>" }; if (text[start] == '<') { outer: for (int i=0; i<breakTags.length; ++i) { String tag = breakTags[i]; int len = tag.length(); if (start + len < end) { for (int j=0; j<len; ++j) { char c = tag.charAt(j); if (Character.toLowerCase(text[start + 1 + j]) != c) { continue outer; } } return true; } } } return false; } //private static final StringBuffer buf=new StringBuffer(32768); private static final StringBuffer whitespaceBuf=new StringBuffer(); private static char[] charBuf = new char[60000]; private static int bufPos = 0; private static void appendToBuf(char c) { if (bufPos < charBuf.length) { charBuf[bufPos++] = c; } else { // } } private static void appendToBuf(StringBuffer s) { if (bufPos + s.length() <= charBuf.length) { s.getChars(0, s.length(), charBuf, bufPos); bufPos += s.length(); } else { // } } private static void setBufLength(int length) { bufPos = 0; } private static String bufToString() { return new String(charBuf, 0, bufPos); } private static int bufLength() { return bufPos; } public static Map parseCommentTags(char[] comment, int startIndex, int endIndex, ClassDocImpl contextClass, MemberDocImpl contextMember, AbstractTagImpl contextTag, String boilerplateComment) { int rawDocStart=skipHtmlWhitespace(comment, startIndex); int firstSentenceEnd = 0; if (comment.length>rawDocStart) { firstSentenceEnd = findEndOfSentence(comment, rawDocStart, comment.length); if (firstSentenceEnd < 0) { BreakIterator boundary = BreakIterator.getSentenceInstance(Locale.ENGLISH); boundary.setText(new ArrayCharacterIterator(comment, rawDocStart)); boundary.first(); boundary.next(); firstSentenceEnd = boundary.current(); } // Always include period at end of sentence if there is one. if (firstSentenceEnd < comment.length && '.' == comment[firstSentenceEnd]) { ++ firstSentenceEnd; } } final int STATE_BEGOFLINE = 1; final int STATE_TEXT = 2; final int STATE_PARAM = 3; final int STATE_PARAMVALUE = 4; final int STATE_PARAMWRAP = 5; final int STATE_INLINEPARAM = 6; final int STATE_INLINEPARAMVALUE = 7; final int STATE_WHITESPACE = 8; final int STATE_INLINEPARAMVALUE_BOL = 9; final int STATE_IPV_WHITESPACE = 10; int state=STATE_BEGOFLINE; int prevState=STATE_TEXT; setBufLength(0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -