Class SourceCode
- java.lang.Object
-
- org.apache.openjpa.persistence.util.SourceCode
-
public class SourceCode extends java.lang.Object
A utility to help writing Java Source code dynamically. Provides basic elements of Java Source Code e.g. Package, Class, Field, Method, Import, Annotation, Argument. Mutator methods return the operating element for easy chaining.- Since:
- 2.0.0
- Author:
- Pinaki Poddar
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SourceCode.ACCESS
class
SourceCode.Annotation
Represents annotation.class
SourceCode.Argument<K,V>
Represents method argument.class
SourceCode.Class
Representclass
declaration.class
SourceCode.Constructor
class
SourceCode.Element<T>
Abstract element has a name, optional list of modifiers, annotations and arguments.class
SourceCode.Field
Represents field declaration.class
SourceCode.Method
Represents Method declaration.
-
Constructor Summary
Constructors Constructor Description SourceCode(java.lang.String c)
Create source code for a top-level class with given fully-qualified class name.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description SourceCode
addComment(boolean inline, java.lang.String... lines)
org.apache.openjpa.persistence.util.SourceCode.ClassName
getOrCreateImport(java.lang.String name)
Get the class name instance for the given fully-qualified class name.org.apache.openjpa.persistence.util.SourceCode.Package
getPackage()
SourceCode.Class
getTopLevelClass()
Gets the top level class represented by this receiver.static boolean
isJavaIdentifier(java.lang.String s)
static boolean
isKnownType(java.lang.String s)
SourceCode
setTabSize(int t)
Sets the tab size.static java.lang.String[]
wrap(java.lang.String longLine, int width)
Wraps the given string into lines of max length width at word boundariesvoid
write(java.io.PrintWriter out)
Prints the class to the given Writer.
-
-
-
Field Detail
-
COMMA
public static final java.lang.String COMMA
- See Also:
- Constant Field Values
-
DOT
public static final java.lang.String DOT
- See Also:
- Constant Field Values
-
EQUAL
public static final java.lang.String EQUAL
- See Also:
- Constant Field Values
-
QUOTE
public static final java.lang.String QUOTE
- See Also:
- Constant Field Values
-
-
Method Detail
-
getTopLevelClass
public SourceCode.Class getTopLevelClass()
Gets the top level class represented by this receiver.
-
getPackage
public org.apache.openjpa.persistence.util.SourceCode.Package getPackage()
-
setTabSize
public SourceCode setTabSize(int t)
Sets the tab size. Tabs are always written as spaces.
-
getOrCreateImport
public org.apache.openjpa.persistence.util.SourceCode.ClassName getOrCreateImport(java.lang.String name)
Get the class name instance for the given fully-qualified class name. If the given class name is already imported, then use the existing instance. Otherwise, creates a new instance and adds it to list of imports.- Parameters:
name
- fully-qualified name of a class- Returns:
- an existing class name instance or a new one.
- See Also:
addImport(ClassName)
,SourceCode.ClassName
-
addComment
public SourceCode addComment(boolean inline, java.lang.String... lines)
-
write
public void write(java.io.PrintWriter out)
Prints the class to the given Writer.- Parameters:
out
-
-
wrap
public static java.lang.String[] wrap(java.lang.String longLine, int width)
Wraps the given string into lines of max length width at word boundaries
-
isKnownType
public static boolean isKnownType(java.lang.String s)
-
isJavaIdentifier
public static boolean isJavaIdentifier(java.lang.String s)
-
-