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: /**
012: * Store a portion of a javadoc item
013: *
014: *@author Chris Seguin
015: *@created April 15, 1999
016: */
017: public class NamedJavaDocComponent extends JavaDocComponent {
018: // Instance Variable
019: private String id;
020:
021: /**
022: * Create an instance of this java doc object
023: */
024: public NamedJavaDocComponent() {
025: super ();
026: id = "";
027: }
028:
029: /**
030: * Set the id
031: *
032: *@param newID the new id
033: */
034: public void setID(String newID) {
035: if (newID != null) {
036: id = newID;
037: setLongestLength(getType().length() + id.length() + 2);
038: }
039: }
040:
041: /**
042: * Return the id
043: *
044: *@return the id
045: */
046: public String getID() {
047: return id;
048: }
049:
050: /**
051: * Print this tag
052: *
053: *@param printData printData
054: */
055: public void print(PrintData printData) {
056: // We are now printing it
057: setPrinted(true);
058:
059: // Start the line
060: printData.indent();
061: if (!printData.isStarsAlignedWithSlash()) {
062: printData.space();
063: }
064: printData.appendComment("*", PrintData.JAVADOC_COMMENT);
065:
066: if (printData.isSpaceBeforeAt()) {
067: printData.appendComment(" ", PrintData.JAVADOC_COMMENT);
068: }
069:
070: // Print the type
071: printData.appendComment(getType(), PrintData.JAVADOC_COMMENT);
072: for (int i = 0; i < printData.getJavadocIndent(); ++i) {
073: printData.appendComment(" ", PrintData.JAVADOC_COMMENT);
074: }
075:
076: // Print the ID
077: printData.appendComment(getID(), PrintData.JAVADOC_COMMENT);
078:
079: if (!printData.isJavadocLinedUp() && getID().length() > 0) {
080: // Add a space after "param foo", "throws exc", etc.
081: printData.appendComment(" ", PrintData.JAVADOC_COMMENT);
082: } else if (printData.isKeepErroneousJavadocTags()
083: && getType().endsWith("error")) {
084: printData.appendComment(" ", PrintData.JAVADOC_COMMENT);
085: }
086:
087: if (printData.isJavadocDescriptionLinedup()) {
088: LineUpIndent(printData);
089: } else {
090: NoLineUpIndent(printData);
091: }
092:
093: printData.newline();
094: }
095:
096: /**
097: * The indent lines should line up
098: *
099: *@param printData the print data
100: */
101: private void LineUpIndent(PrintData printData) {
102: if (printData.isJavadocLinedUp()) {
103: // Pad extra spaces after the ID
104: int extra = getLongestLength()
105: - (getType().length() + getID().length()) - 1;
106: for (int ndx = 0; ndx < extra; ndx++) {
107: printData.appendComment(" ", PrintData.JAVADOC_COMMENT);
108: }
109:
110: // word wrap the description with the proper indent
111: int indent = getLongestLength();
112:
113: if (printData.isSpaceBeforeAt()) {
114: // we need to take into account the leading space before "@" if present
115: indent++;
116: }
117:
118: wordwrapDescription(printData, indent);
119: } else {
120: // Print the description, no line up
121: printDescription(printData);
122: }
123: }
124:
125: /**
126: * This is the old style javadoc line up
127: *
128: *@param printData the print data
129: */
130: private void NoLineUpIndent(PrintData printData) {
131: if (printData.isJavadocLinedUp()) {
132: // Pad extra spaces after the ID
133: int extra = getLongestLength()
134: - (getType().length() + getID().length());
135: for (int ndx = 0; ndx < extra; ndx++) {
136: printData.appendComment(" ", PrintData.JAVADOC_COMMENT);
137: }
138: }
139:
140: // Print the description
141: printDescription(printData);
142: }
143: }
144: /*******\
145: \*******/
|