Class SourceCode


  • public class SourceCode
    extends 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
    • Constructor Detail

      • SourceCode

        public SourceCode​(String c)
        Create source code for a top-level class with given fully-qualified class name.
    • 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​(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,
                                     String... lines)
      • write

        public void write​(PrintWriter out)
        Prints the class to the given Writer.
        Parameters:
        out -
      • wrap

        public static String[] wrap​(String longLine,
                                    int width)
        Wraps the given string into lines of max length width at word boundaries
      • isKnownType

        public static boolean isKnownType​(String s)
      • isJavaIdentifier

        public static boolean isJavaIdentifier​(String s)