View Javadoc

1   //Copyright 2007-2008, by the California Institute of Technology.
2   //ALL RIGHTS RESERVED. United States Government Sponsorship acknowledged.
3   //Any commercial use must be negotiated with the Office of Technology Transfer
4   //at the California Institute of Technology.
5   //
6   //This software is subject to U. S. export control laws and regulations
7   //(22 C.F.R. 120-130 and 15 C.F.R. 730-774). To the extent that the software
8   //is subject to U.S. export control laws and regulations, the recipient has
9   //the responsibility to obtain export licenses or other export authority as
10  //may be required before exporting such information to foreign countries or
11  //providing access to foreign nationals.
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  		//TODO: Throw an error if the equals position was set.
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  }