Class CodeFragment

java.lang.Object
org.faktorips.codegen.CodeFragment
Direct Known Subclasses:
JavaCodeFragment

public class CodeFragment extends Object
Represents a language independent source code fragment. A source code fragment consists of the source code text and possibly additional parts like import statements. The default implementation is the JavaCodeFragment.
See Also:
  • Constructor Details

    • CodeFragment

      public CodeFragment()
      Creates a new empty JavaCodeFragment.
    • CodeFragment

      public CodeFragment(boolean indent)
    • CodeFragment

      public CodeFragment(String sourcecode)
      Creates a new CodeFragment with the indicated source code.
    • CodeFragment

      public CodeFragment(CodeFragment fragment)
      Copy constructor.
  • Method Details

    • getSourcecode

      public String getSourcecode()
      Returns the sourcecode.
    • incIndentationLevel

      public void incIndentationLevel()
      Increases the indentation level used for appending sourcecode.
    • decIndentationLevel

      public void decIndentationLevel()
      Decreases the indentation level used for appending sourcecode.
      Throws:
      RuntimeException - if the level is 0.
    • getIndentationLevel

      public int getIndentationLevel()
      Returns the current indentation level at the end of the sourcecode.
    • append

      public CodeFragment append(String s)
      Appends the given String to the source code.
    • appendJoined

      public CodeFragment appendJoined(Iterable<?> iterable)
      Appends the given Iterable's content converted to String and separated by ", " to the source code.
    • appendJoined

      public CodeFragment appendJoined(Object[] array)
      Appends the given array's content converted to String and separated by ", " to the source code.
    • appendQuoted

      public CodeFragment appendQuoted(String s)
      Encloses the given String with double quotes (") and appends it to the source code.
    • append

      public CodeFragment append(char c)
      Appends the given char to the source code.
    • appendln

      public CodeFragment appendln()
      Appends a line separator to the source code.
    • appendln

      public CodeFragment appendln(String s)
      Appends the given String and a line separator to the source code.
    • appendlnUnindented

      public CodeFragment appendlnUnindented(String arg)
      Appends the given String as is to the source code without indenting it.
    • appendln

      public CodeFragment appendln(char c)
      Appends the given char to the source code.
    • append

      public CodeFragment append(CodeFragment fragment)
      Appends the given fragment to his fragment and indents it properly.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Two fragments are equal if they contain the same sourcecode and have the same import declaration.
      Overrides:
      equals in class Object
    • bol

      public boolean bol()
      Returns true if the last character in the source code is a line separator and so any text appended to the source code goes to a new line (bol = begin of line).
    • toString

      public String toString()
      Returns the CodeFragment as String.
      Overrides:
      toString in class Object
      See Also: