Class DefaultJavaSource

  • All Implemented Interfaces:
    JavaSource, java.io.Serializable

    public class DefaultJavaSource
    extends java.lang.Object
    implements JavaSource, java.io.Serializable
    See Also:
    Serialized Form
    • Field Detail

      • imports

        private final java.util.List<java.lang.String> imports
      • classes

        private java.util.List<JavaClass> classes
      • url

        private java.net.URL url
    • Constructor Detail

      • DefaultJavaSource

        public DefaultJavaSource​(ClassLibrary classLibrary)
        Default constructor for the Default JavaSource
        Parameters:
        classLibrary - the classLibrary, should not be null
    • Method Detail

      • setURL

        public void setURL​(java.net.URL url)
        Parameters:
        url - the URL of the source file
        Since:
        1.4
      • getURL

        public java.net.URL getURL()
        Specified by:
        getURL in interface JavaSource
        Returns:
        the URL of the source file
      • setPackage

        public void setPackage​(JavaPackage pkg)
      • addImport

        public void addImport​(java.lang.String imp)
      • getImports

        public java.util.List<java.lang.String> getImports()
        Retrieve all the import
        Specified by:
        getImports in interface JavaSource
        Returns:
        the imports, never null
      • addClass

        public void addClass​(JavaClass cls)
      • getClasses

        public java.util.List<JavaClass> getClasses()
        A List with all direct classes of this source, never null
        Specified by:
        getClasses in interface JavaSource
        Returns:
        a list of JavaClasses, never null
      • getCodeBlock

        public java.lang.String getCodeBlock()
        Complete code representation of this source
        Specified by:
        getCodeBlock in interface JavaSource
        Returns:
        the code block of this source
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getClassNamePrefix

        public java.lang.String getClassNamePrefix()
        If there's a package, return the packageName, followed by a dot, otherwise an empty String
        Specified by:
        getClassNamePrefix in interface JavaSource
        Returns:
        the class name prefix, otherwise an empty String
      • getNestedClassByName

        public JavaClass getNestedClassByName​(java.lang.String name)
        Try to get the JavaClass child based on its name relative to the package. This doesn't try to resolve it by recursion.
        Specified by:
        getNestedClassByName in interface JavaSource
        Parameters:
        name - the name of the class
        Returns:
        the resolved JavaClass, otherwise null
      • getClassByName

        public JavaClass getClassByName​(java.lang.String name)
        Try to get any class of this source by name. The name can be both the fully qualified name or just the name of the class.
        Specified by:
        getClassByName in interface JavaSource
        Parameters:
        name - the (fully qualified) name of the class
        Returns:
        the matching class, otherwise null
      • getPackageName

        public java.lang.String getPackageName()
        Returns the name of the package or an empty String if there's no package
        Specified by:
        getPackageName in interface JavaSource
        Returns:
        the package name, otherwise an empty String
      • setModelWriterFactory

        public void setModelWriterFactory​(ModelWriterFactory modelWriterFactory)
        Parameters:
        modelWriterFactory - the modelWriterFactory
        Since:
        2.0
      • getModelWriter

        private ModelWriter getModelWriter()