Package org.faktorips.codegen
Class JavaCodeFragment
java.lang.Object
org.faktorips.codegen.CodeFragment
org.faktorips.codegen.JavaCodeFragment
The class represents a Java source code fragment. A source code fragment consists of the source
code text and the import statements needed to compile the text.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new empty JavaCodeFragment.JavaCodeFragment(boolean indent) JavaCodeFragment(String sourcecode) Creates a new JavaCodeFragment with the indicated source code and no import statements.JavaCodeFragment(String sourcecode, ImportDeclaration importDecl) Creates a new JavaCodeFragment with the indicated source code and import declaration.JavaCodeFragment(JavaCodeFragment fragment) Copy constructor.JavaCodeFragment(JavaCodeFragment fragment, String packageName) Constructs a JavaCodeFragment that has the same source code as the given fragment with all import statements removed that are obsolete because of the indicated package. -
Method Summary
Modifier and TypeMethodDescriptionAdds an import entry to this code fragment.append(boolean b) Transform the given boolean into a String and appends it to the source code.append(char c) Appends the given char to the source code.append(int i) Transform the given int into a String and appends it to the source code.Appends the given String to the source code.append(CodeFragment fragment) Appends the given fragment to his fragment and indents it properly.append(JavaCodeFragment fragment) Appends the given fragment to his fragment and indents it properly.appendClassName(Class<?> clazz) Appends the unqualified class name to the source code and updates the import declaration (if necessary).appendClassName(String qualifiedClassName) Appends the unqualified class name to the source code and updates the import declaration (if necessary).Appends '}' to the source code and decreases the indentation level.appendInnerClassName(Class<?> clazz) Appends the unqualified class name of an public inner class to the source code and updates the import declaration (if necessary).appendInnerClassName(String qualifiedClassName) Appends the unqualified class name of an public inner class to the source code and updates the import declaration (if necessary).appendJoined(Iterable<?> iterable) Appends the givenIterable's content converted to String and separated by ", " to the source code.appendJoined(Object[] array) Appends the given array's content converted to String and separated by ", " to the source code.appendJoined(JavaCodeFragment[] javaCodeFragments) appendln()Appends a line separator to the source code.appendln(char c) Appends the given char to the source code.Appends the given String and a line separator to the source code.appendlnUnindented(String arg) Appends the given String as is to the source code without indenting it.Appends '{' to the source code and increases the indentation level.Encloses the given String with double quotes (") and appends it to the source code.booleanTwo fragments are equal if they contain the same source code and have the same import declaration.Returns the import declaration needed to compile the source code.getImportDeclaration(String packageName) Returns the import declaration needed to compile the source code.inthashCode()toString()Returns the CodeFragment as String in "normal" Java style, that means first all import statements, new line, than the source code.Methods inherited from class org.faktorips.codegen.CodeFragment
bol, decIndentationLevel, getIndentationLevel, getSourcecode, incIndentationLevel
-
Constructor Details
-
JavaCodeFragment
public JavaCodeFragment()Creates a new empty JavaCodeFragment. -
JavaCodeFragment
public JavaCodeFragment(boolean indent) -
JavaCodeFragment
Creates a new JavaCodeFragment with the indicated source code and no import statements. -
JavaCodeFragment
Creates a new JavaCodeFragment with the indicated source code and import declaration. -
JavaCodeFragment
Constructs a JavaCodeFragment that has the same source code as the given fragment with all import statements removed that are obsolete because of the indicated package. -
JavaCodeFragment
Copy constructor.
-
-
Method Details
-
getImportDeclaration
Returns the import declaration needed to compile the source code. -
getImportDeclaration
Returns the import declaration needed to compile the source code. The returned import declaration does not contain any import statements that refer to the indicated packageName. The method is useful to avoid unnecessary import statements. -
appendOpenBracket
Appends '{' to the source code and increases the indentation level. -
appendCloseBracket
Appends '}' to the source code and decreases the indentation level. -
append
Description copied from class:CodeFragmentAppends the given String to the source code.- Overrides:
appendin classCodeFragment
-
appendJoined
Description copied from class:CodeFragmentAppends the givenIterable's content converted to String and separated by ", " to the source code.- Overrides:
appendJoinedin classCodeFragment
-
appendJoined
Description copied from class:CodeFragmentAppends the given array's content converted to String and separated by ", " to the source code.- Overrides:
appendJoinedin classCodeFragment
-
appendJoined
-
appendQuoted
Description copied from class:CodeFragmentEncloses the given String with double quotes (") and appends it to the source code.- Overrides:
appendQuotedin classCodeFragment
-
append
Description copied from class:CodeFragmentAppends the given char to the source code.- Overrides:
appendin classCodeFragment
-
appendln
Description copied from class:CodeFragmentAppends a line separator to the source code.- Overrides:
appendlnin classCodeFragment
-
appendln
Description copied from class:CodeFragmentAppends the given String and a line separator to the source code.- Overrides:
appendlnin classCodeFragment
-
appendlnUnindented
Description copied from class:CodeFragmentAppends the given String as is to the source code without indenting it.- Overrides:
appendlnUnindentedin classCodeFragment
-
appendln
Description copied from class:CodeFragmentAppends the given char to the source code.- Overrides:
appendlnin classCodeFragment
-
append
Transform the given int into a String and appends it to the source code. -
append
Transform the given boolean into a String and appends it to the source code. -
appendClassName
Appends the unqualified class name to the source code and updates the import declaration (if necessary).- Throws:
NullPointerException- if clazz is null.
-
appendInnerClassName
Appends the unqualified class name of an public inner class to the source code and updates the import declaration (if necessary).- Throws:
NullPointerException- if clazz is null.
-
appendInnerClassName
Appends the unqualified class name of an public inner class to the source code and updates the import declaration (if necessary).- Throws:
NullPointerException- if qualifiedClassName is null.
-
appendClassName
Appends the unqualified class name to the source code and updates the import declaration (if necessary). A [] appended at the end of the qualified class name indicates the array of this type. The brackets are added correctly at the end of the class name in the source code.- Throws:
NullPointerException- if qualifiedClassName is null.
-
addImport
Adds an import entry to this code fragment.- Parameters:
qualifiedClassName- the java class that is added to the import declaration
-
append
Appends the given fragment to his fragment and indents it properly.- Overrides:
appendin classCodeFragment
-
append
Appends the given fragment to his fragment and indents it properly. -
hashCode
public int hashCode()- Overrides:
hashCodein classCodeFragment
-
equals
Two fragments are equal if they contain the same source code and have the same import declaration.- Overrides:
equalsin classCodeFragment
-
toString
Returns the CodeFragment as String in "normal" Java style, that means first all import statements, new line, than the source code.- Overrides:
toStringin classCodeFragment- See Also:
-