01: /*
02: * Copyright 2006 Ralf Joachim
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package org.exolab.javasource;
17:
18: /**
19: * Represents a line of code, used by JSourceCode class.
20: *
21: * @author <a href="mailto:ralf DOT joachim AT syscon DOT eu">Ralf Joachim</a>
22: * @version $Revision: 6668 $ $Date: 2005-05-08 12:32:06 -0600 (Sun, 08 May 2005) $
23: * @since 1.1
24: */
25: public final class JCodeStatement {
26: //--------------------------------------------------------------------------
27:
28: /** Contents of this code statement. */
29: private final StringBuffer _value;
30:
31: /** Indentation depth of this statement. */
32: private short _indentSize = JSourceCode.DEFAULT_INDENT_SIZE;
33:
34: //--------------------------------------------------------------------------
35:
36: JCodeStatement() {
37: super ();
38:
39: _value = new StringBuffer();
40: }
41:
42: JCodeStatement(final String statement) {
43: this ();
44:
45: _value.append(statement);
46: }
47:
48: JCodeStatement(final String statement, final short indentSize) {
49: this (statement);
50:
51: _indentSize = indentSize;
52: }
53:
54: //--------------------------------------------------------------------------
55:
56: void append(final String segment) {
57: _value.append(segment);
58: }
59:
60: short getIndent() {
61: return _indentSize;
62: }
63:
64: String getStatement() {
65: return _value.toString();
66: }
67:
68: //--------------------------------------------------------------------------
69:
70: /**
71: * {@inheritDoc}
72: */
73: public String toString() {
74: StringBuffer sb = new StringBuffer(_indentSize
75: + _value.length());
76: for (int i = 0; i < _indentSize; i++) {
77: sb.append(' ');
78: }
79: sb.append(_value.toString());
80: return sb.toString();
81: }
82:
83: //--------------------------------------------------------------------------
84: }
|