001: /*
002: * Author: Chris Seguin
003: *
004: * This software has been developed under the copyleft
005: * rules of the GNU General Public License. Please
006: * consult the GNU General Public License for more
007: * details about use and distribution of this software.
008: */
009: package org.acm.seguin.pretty;
010:
011: import net.sourceforge.jrefactory.parser.Token;
012:
013: /**
014: * Store a portion of a javadoc item
015: *
016: *@author Mike Atkinson
017: *@created June 22, 2003
018: *@since JRefactory 2.7.02
019: */
020: public class XDocletJavaDocComponent extends JavaDocComponent {
021:
022: /**
023: * Create an instance of this java doc object
024: */
025: public XDocletJavaDocComponent() {
026: super ();
027: }
028:
029: /**
030: * Set the type
031: *
032: *@param newType the new type
033: */
034: public void setType(String newType) {
035: super .setType(newType);
036: setLongestLength(8);
037: }
038:
039: /**
040: * Print this tag
041: *
042: *@param printData printData
043: */
044: public void print(PrintData printData) {
045: // We are now printing it
046: setPrinted(true);
047:
048: // Start the line
049: printData.indent();
050: if (!printData.isStarsAlignedWithSlash()) {
051: printData.space();
052: }
053: printData.appendComment("*", PrintData.JAVADOC_COMMENT);
054:
055: if (printData.isSpaceBeforeAt()) {
056: printData.appendComment(" ", PrintData.JAVADOC_COMMENT);
057: }
058:
059: // Print the type
060: printData.appendComment(getType(), PrintData.JAVADOC_COMMENT);
061: for (int i = 0; i < printData.getJavadocIndent(); ++i) {
062: printData.appendComment(" ", PrintData.JAVADOC_COMMENT);
063: }
064:
065: // Break into lines
066: StringBuffer sb = new StringBuffer();
067: boolean startOnNewLine = false;
068: int state = 0;
069: XDocletTokenizer tok = new XDocletTokenizer(getDescription());
070: while (tok.hasNext()) {
071: Token next = tok.next();
072:
073: if ((next.image == null) || (next.image.length() == 0)) {
074: // Do nothing
075: } else if (next.image.equals("=")) {
076: //System.out.println("kind="+next.kind+", state="+state+", next.image="+next.image);
077: startOnNewLine = true;
078: // System.out.println(" appending \" = \"");
079: sb.append(" ");
080: sb.append("=");
081: sb.append(" ");
082: state = 2;
083: } else if (next.kind == XDocletTokenizer.SPACE) {
084: } else if (next.kind == XDocletTokenizer.NEWLINE) {
085: //System.out.println("kind="+next.kind+", state="+state+", next.image="+next.image);
086: if (state != 0 && startOnNewLine) {
087: //System.out.println(" appending \""+next.image+"\"");
088: sb.append(next.image);
089: state = 0;
090: }
091: } else if (next.image.trim().equals("*")) {
092: //System.out.println("kind="+next.kind+", state="+state+", next.image="+next.image);
093: } else {
094: //System.out.println("kind="+next.kind+", state="+state+", next.image="+next.image);
095: //System.out.println(" appending \""+next.image+"\"");
096: sb.append(next.image);
097: state++;
098: if (state == 3) {
099: //System.out.println(" appending \\n");
100: sb.append("\n");
101: state = 0;
102: }
103: }
104: }
105:
106: int oldIndent = printData.getJavadocIndent();
107: if (startOnNewLine) {
108: printData.indent();
109: if (!printData.isStarsAlignedWithSlash()) {
110: printData.space();
111: }
112: printData.appendComment("*", PrintData.JAVADOC_COMMENT);
113: for (int i = 0; i < oldIndent + 6; ++i) {
114: printData.space();
115: }
116: }
117: //System.out.println("printing: \""+sb.toString()+"\"");
118: setDescription(sb.toString());
119: printData.setJavadocIndent(oldIndent + 6); // increment indent
120: leaveDescription(printData);
121: printData.newline();
122: printData.setJavadocIndent(oldIndent); // restore old indent
123:
124: // blank line after Xdoclet comment
125: printData.indent();
126: if (!printData.isStarsAlignedWithSlash()) {
127: printData.space();
128: }
129: printData.appendComment("*", PrintData.JAVADOC_COMMENT);
130: }
131:
132: }
|