All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.exolab.javasource.JCodeStatement Maven / Gradle / Ivy

Go to download

Code generator of Castor XML: takes a set of XML schemas and generates Java source code based on the content definitions

The newest version!
/*
 * Copyright 2006 Ralf Joachim
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package org.exolab.javasource;

/**
 * Represents a line of code, used by JSourceCode class.
 *
 * @author Ralf Joachim
 * @version $Revision: 6668 $ $Date: 2005-05-08 12:32:06 -0600 (Sun, 08 May 2005) $
 * @since 1.1
 */
public final class JCodeStatement {
  // --------------------------------------------------------------------------

  /** Contents of this code statement. */
  private final StringBuffer _value;

  /** Indentation depth of this statement. */
  private short _indentSize = JSourceCode.DEFAULT_INDENT_SIZE;

  // --------------------------------------------------------------------------

  JCodeStatement() {
    super();

    _value = new StringBuffer();
  }

  JCodeStatement(final String statement) {
    this();

    _value.append(statement);
  }

  JCodeStatement(final String statement, final short indentSize) {
    this(statement);

    _indentSize = indentSize;
  }

  // --------------------------------------------------------------------------

  void append(final String segment) {
    _value.append(segment);
  }

  short getIndent() {
    return _indentSize;
  }

  String getStatement() {
    return _value.toString();
  }

  // --------------------------------------------------------------------------

  /**
   * {@inheritDoc}
   */
  public String toString() {
    if (_value.length() == 0) {
      return "";
    }
    StringBuilder sb = new StringBuilder(_indentSize + _value.length());
    for (int i = 0; i < _indentSize; i++) {
      sb.append(' ');
    }
    sb.append(_value);
    return sb.toString();
  }

  // --------------------------------------------------------------------------
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy