1
2
3
4
5
6
7
8
9
10
11
12
13 package gov.nasa.pds.ltdt.label.statement;
14
15 import gov.nasa.pds.ltdt.gui.util.Utility;
16 import gov.nasa.pds.tools.label.CommentStatement;
17
18 /***
19 * Class used to provide a string representation of a comment.
20 *
21 * @author mcayanan
22 *
23 */
24 public class PrettyCommentStatement extends CommentStatement implements PrettyStatement {
25
26 /***
27 * Constructs a CommentStatement.
28 *
29 * @param lineNumber Where the statement is located.
30 * @param identifier The data element name associated with the comment.
31 * @param comment The comment string.
32 */
33 public PrettyCommentStatement(int lineNumber, String identifier, String comment) {
34 super(lineNumber, identifier, comment);
35 }
36
37 /***
38 * Returns a string representation of the comment.
39 */
40 public String toString() {
41 return toString((short) 0, 0);
42 }
43
44 /***
45 * Returns a string representation of the comment with a
46 * given indentation.
47 */
48 public String toString(short indentLength) {
49 return toString(indentLength, 0);
50 }
51
52 /***
53 * Returns a string representation of the comment. The equals
54 * position should always be set to zero since comments don't have equals.
55 *
56 * @throws IllegalArgumentException If the equalsPosition variable is set
57 * to a number other than zero.
58 */
59 public String toString(short indentLength, int equalsPosition) {
60
61 if(equalsPosition != 0) {
62 throw new IllegalArgumentException
63 ("PrettyCommentStatement: Equals sign should not be set.");
64 }
65 String comment = "/* " + getComment() + " */";
66 comment = Utility.addLeadingWhiteSpace(comment, indentLength);
67 return comment;
68 }
69 }