Class JavaFile


  • public final class JavaFile
    extends java.lang.Object
    A Java file containing a single top level class.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  JavaFile.Builder  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static JavaFile.Builder builder​(java.lang.String packageName, TypeSpec typeSpec)  
      private void emit​(CodeWriter codeWriter)  
      boolean equals​(java.lang.Object o)  
      private void fillAlwaysQualifiedNames​(TypeSpec spec, java.util.Set<java.lang.String> alwaysQualifiedNames)  
      int hashCode()  
      JavaFile.Builder toBuilder()  
      javax.tools.JavaFileObject toJavaFileObject()  
      java.lang.String toString()  
      void writeTo​(java.io.File directory)
      Writes this to directory as UTF-8 using the standard directory structure.
      void writeTo​(java.lang.Appendable out)  
      void writeTo​(java.nio.file.Path directory)
      Writes this to directory as UTF-8 using the standard directory structure.
      void writeTo​(java.nio.file.Path directory, java.nio.charset.Charset charset)
      Writes this to directory with the provided charset using the standard directory structure.
      void writeTo​(javax.annotation.processing.Filer filer)
      Writes this to filer.
      java.io.File writeToFile​(java.io.File directory)
      Writes this to directory as UTF-8 using the standard directory structure.
      java.nio.file.Path writeToPath​(java.nio.file.Path directory)
      Writes this to directory as UTF-8 using the standard directory structure.
      java.nio.file.Path writeToPath​(java.nio.file.Path directory, java.nio.charset.Charset charset)
      Writes this to directory with the provided charset using the standard directory structure.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • NULL_APPENDABLE

        private static final java.lang.Appendable NULL_APPENDABLE
      • fileComment

        public final CodeBlock fileComment
      • packageName

        public final java.lang.String packageName
      • typeSpec

        public final TypeSpec typeSpec
      • skipJavaLangImports

        public final boolean skipJavaLangImports
      • staticImports

        private final java.util.Set<java.lang.String> staticImports
      • alwaysQualify

        private final java.util.Set<java.lang.String> alwaysQualify
      • indent

        private final java.lang.String indent
    • Method Detail

      • fillAlwaysQualifiedNames

        private void fillAlwaysQualifiedNames​(TypeSpec spec,
                                              java.util.Set<java.lang.String> alwaysQualifiedNames)
      • writeTo

        public void writeTo​(java.lang.Appendable out)
                     throws java.io.IOException
        Throws:
        java.io.IOException
      • writeTo

        public void writeTo​(java.nio.file.Path directory)
                     throws java.io.IOException
        Writes this to directory as UTF-8 using the standard directory structure.
        Throws:
        java.io.IOException
      • writeTo

        public void writeTo​(java.nio.file.Path directory,
                            java.nio.charset.Charset charset)
                     throws java.io.IOException
        Writes this to directory with the provided charset using the standard directory structure.
        Throws:
        java.io.IOException
      • writeToPath

        public java.nio.file.Path writeToPath​(java.nio.file.Path directory)
                                       throws java.io.IOException
        Writes this to directory as UTF-8 using the standard directory structure. Returns the Path instance to which source is actually written.
        Throws:
        java.io.IOException
      • writeToPath

        public java.nio.file.Path writeToPath​(java.nio.file.Path directory,
                                              java.nio.charset.Charset charset)
                                       throws java.io.IOException
        Writes this to directory with the provided charset using the standard directory structure. Returns the Path instance to which source is actually written.
        Throws:
        java.io.IOException
      • writeTo

        public void writeTo​(java.io.File directory)
                     throws java.io.IOException
        Writes this to directory as UTF-8 using the standard directory structure.
        Throws:
        java.io.IOException
      • writeToFile

        public java.io.File writeToFile​(java.io.File directory)
                                 throws java.io.IOException
        Writes this to directory as UTF-8 using the standard directory structure. Returns the File instance to which source is actually written.
        Throws:
        java.io.IOException
      • writeTo

        public void writeTo​(javax.annotation.processing.Filer filer)
                     throws java.io.IOException
        Writes this to filer.
        Throws:
        java.io.IOException
      • emit

        private void emit​(CodeWriter codeWriter)
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

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

        public javax.tools.JavaFileObject toJavaFileObject()