com.jogamp.gluegen

## Class JavaEmitter

- java.lang.Object
- - com.jogamp.gluegen.JavaEmitter

- All Implemented Interfaces:
    GlueEmitter
  Direct Known Subclasses:
    CStructAnnotationProcessor.AnnotationProcessorJavaStructEmitter, ProcAddressEmitter

      public class JavaEmitter
      extends Object
      implements GlueEmitter

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `JavaEmitter.EmissionStyle` Style of code emission.
    `static class` | `JavaEmitter.MethodAccess` Access control for emitted Java methods.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected JavaConfiguration` | `cfg`
    `protected static Logger` | `LOG`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `JavaEmitter()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static int` | `addStrings2Buffer(StringBuilder buf, String sep, String first, Collection<String> col)`
    `void` | `beginDefines()`
    `void` | `beginEmission(GlueEmitterControls controls)` Begin the emission of glue code.
    `void` | `beginFunctions(TypeDictionary typedefDictionary, TypeDictionary structDictionary, Map<Type,Type> canonMap)`
    `void` | `beginStructLayout()` Begins the process of computing field offsets and type sizes for the structs to be emitted.
    `void` | `beginStructs(TypeDictionary typedefDictionary, TypeDictionary structDictionary, Map<Type,Type> canonMap)`
    `protected JavaConfiguration` | `createConfig()` Create the object that will read and store configuration information for this JavaEmitter.
    `protected PrintWriter` | `cWriter()`
    `protected void` | `emitAllFileFooters()` Write out any footer information for the output files (closing brace of class definition, etc).
    `protected void` | `emitAllFileHeaders()` Write out any header information for the output files (class declaration and opening brace, import statements, etc).
    `protected void` | `emitCHeader(PrintWriter cWriter, String packageName, String className)`
    `protected void` | `emitCInitCode(PrintWriter cWriter, String packageName, String className)`
    `protected void` | `emitCustomJavaCode(PrintWriter writer, String className)` Emit all the strings specified in the "CustomJavaCode" parameters of the configuration file.
    `void` | `emitDefine(ConstantDefinition def, String optionalComment)`
    `Iterator<FunctionSymbol>` | `emitFunctions(List<FunctionSymbol> originalCFunctions)` Emit glue code for the list of FunctionSymbols.
    `protected void` | `emitJavaInitCode(PrintWriter jWriter, String className)`
    `void` | `emitStruct(CompoundType structCType, String alternateName)` Emit glue code for the given CompoundType.
    `void` | `endDefines()`
    `void` | `endEmission()` Finish the emission of glue code.
    `void` | `endFunctions()`
    `void` | `endStructLayout()` Finishes the struct layout process.
    `void` | `endStructs()`
    `protected List<MethodBinding>` | `expandMethodBinding(MethodBinding binding)`
    `protected List<? extends FunctionEmitter>` | `generateMethodBindingEmitters(Set<MethodBinding> methodBindingSet, FunctionSymbol sym)` Generate all appropriate Java bindings for the specified C function symbols.
    `protected void` | `generatePrivateEmitters(MethodBinding binding, List<FunctionEmitter> allEmitters)` Generates the private emitters for this MethodBinding.
    `protected void` | `generatePublicEmitters(MethodBinding binding, List<FunctionEmitter> allEmitters, boolean signatureOnly)` Generates the public emitters for this MethodBinding which will produce either simply signatures (for the interface class, if any) or function definitions with or without a body (depending on whether or not the implementing function can go directly to native code because it doesn't need any processing of the outgoing arguments).
    `protected JavaConfiguration` | `getConfig()` Get the configuration information for this JavaEmitter.
    `protected String` | `getImplPackageName()` Returns the value that was specified by the configuration directive "ImplPackage", or the default if none was specified.
    `protected String` | `getJavaOutputDir()` Returns the value that was specified by the configuration directive "JavaOutputDir", or the default if none was specified.
    `protected String` | `getJavaPackageName()` Returns the value that was specified by the configuration directive "Package", or the default if none was specified.
    `protected static int` | `getJavaRadix(String name, String value)`
    `protected static String` | `getJavaType(String name, Object oval)`
    `protected static String` | `getJavaType(String name, String value)`
    `protected static Object` | `getJavaValue(String name, String value)`
    `protected static String` | `getJNIMethodNamePrefix(String javaPackageName, String javaClassName)` Returns the JNI method prefix consisting our of mangled package- and class-name
    `protected PrintWriter` | `javaImplWriter()`
    `protected PrintWriter` | `javaWriter()`
    `protected static String` | `jniMangle(String name)` Mangle a class, package or function name for JNI usage, i.e.
    `void` | `layoutStruct(CompoundType t)` Lays out one struct which will be emitted later.
    `protected PrintWriter` | `openFile(String filename, String simpleClassName)`
    `protected void` | `prepCEmitter(String returnSizeLookupName, JavaType javaReturnType, CMethodBindingEmitter cEmitter)`
    `void` | `readConfigurationFile(String filename)`
    `protected boolean` | `requiresStaticInitialization(String clazzName)` Returns `true` if implementation (java and native-code) requires `staticClassInitCodeCCode` and `staticClassInitCallJavaCode` and have `initializeImpl()` being called at static class initialization.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### cfg

          protected JavaConfiguration cfg

    - #### LOG

          protected static final Logger LOG

  - ### Constructor Detail

    - #### JavaEmitter

          public JavaEmitter()

  - ### Method Detail

    - #### readConfigurationFile

          public void readConfigurationFile(String filename)
                                     throws Exception

      Specified by:
        `readConfigurationFile` in interface `GlueEmitter`
      Throws:
        `Exception`

    - #### beginEmission

          public void beginEmission(GlueEmitterControls controls)
                             throws IOException

      Description copied from interface: `GlueEmitter`
      Begin the emission of glue code. This might include opening files, emitting class headers, etc.
      Specified by:
        `beginEmission` in interface `GlueEmitter`
      Throws:
        `IOException`

    - #### endEmission

          public void endEmission()

      Description copied from interface: `GlueEmitter`
      Finish the emission of glue code. This might include closing files, closing open class definitions, etc.
      Specified by:
        `endEmission` in interface `GlueEmitter`

    - #### beginDefines

          public void beginDefines()
                            throws Exception

      Specified by:
        `beginDefines` in interface `GlueEmitter`
      Throws:
        `Exception`

    - #### getJavaRadix

          protected static int getJavaRadix(String name,
                         String value)

    - #### getJavaValue

          protected static Object getJavaValue(String name,
                            String value)

    - #### getJavaType

          protected static String getJavaType(String name,
                           String value)

    - #### getJavaType

          protected static String getJavaType(String name,
                           Object oval)

    - #### jniMangle

          protected static String jniMangle(String name)

      Mangle a class, package or function name for JNI usage, i.e. replace all '.' w/ '_'

    - #### getJNIMethodNamePrefix

          protected static String getJNIMethodNamePrefix(String javaPackageName,
                                      String javaClassName)

      Returns the JNI method prefix consisting our of mangled package- and class-name

    - #### emitDefine

          public void emitDefine(ConstantDefinition def,
                        String optionalComment)
                          throws Exception

      Specified by:
        `emitDefine` in interface `GlueEmitter`
        `optionalComment` - If optionalComment is non-null, the emitter can emit that string as a comment providing extra information about the define.
      Throws:
        `Exception`

    - #### endDefines

          public void endDefines()
                          throws Exception

      Specified by:
        `endDefines` in interface `GlueEmitter`
      Throws:
        `Exception`

    - #### beginFunctions

          public void beginFunctions(TypeDictionary typedefDictionary,
                            TypeDictionary structDictionary,
                            Map<Type,Type> canonMap)
                              throws Exception

      Specified by:
        `beginFunctions` in interface `GlueEmitter`
      Throws:
        `Exception`

    - #### emitFunctions

          public Iterator<FunctionSymbol> emitFunctions(List<FunctionSymbol> originalCFunctions)
                                                 throws Exception

      Description copied from interface: `GlueEmitter`
      Emit glue code for the list of FunctionSymbols.
      Specified by:
        `emitFunctions` in interface `GlueEmitter`
      Throws:
        `Exception`

    - #### createConfig

          protected JavaConfiguration createConfig()

      Create the object that will read and store configuration information for this JavaEmitter.

    - #### getConfig

          protected JavaConfiguration getConfig()

      Get the configuration information for this JavaEmitter.

    - #### requiresStaticInitialization

          protected final boolean requiresStaticInitialization(String clazzName)

      Returns `true` if implementation (java and native-code) requires `staticClassInitCodeCCode` and `staticClassInitCallJavaCode` and have `initializeImpl()` being called at static class initialization.

      This is currently true, if one of the following method returns `true`

      - `one of the binding's signature requires it`
      - `JavaConfiguration.forceStaticInitCode(String)`

    - #### generatePublicEmitters

          protected void generatePublicEmitters(MethodBinding binding,
                                    List<FunctionEmitter> allEmitters,
                                    boolean signatureOnly)

      Generates the public emitters for this MethodBinding which will produce either simply signatures (for the interface class, if any) or function definitions with or without a body (depending on whether or not the implementing function can go directly to native code because it doesn't need any processing of the outgoing arguments).

    - #### generatePrivateEmitters

          protected void generatePrivateEmitters(MethodBinding binding,
                                     List<FunctionEmitter> allEmitters)

      Generates the private emitters for this MethodBinding. On the Java side these will simply produce signatures for native methods. On the C side these will create the emitters which will write the JNI code to interface to the functions. We need to be careful to make the signatures all match up and not produce too many emitters which would lead to compilation errors from creating duplicated methods / functions.

    - #### prepCEmitter

          protected void prepCEmitter(String returnSizeLookupName,
                          JavaType javaReturnType,
                          CMethodBindingEmitter cEmitter)

    - #### generateMethodBindingEmitters

          protected List<? extends FunctionEmitter> generateMethodBindingEmitters(Set<MethodBinding> methodBindingSet,
                                                                      FunctionSymbol sym)
                                                                           throws Exception

      Generate all appropriate Java bindings for the specified C function symbols.
      Throws:
        `Exception`

    - #### endFunctions

          public void endFunctions()
                            throws Exception

      Specified by:
        `endFunctions` in interface `GlueEmitter`
      Throws:
        `Exception`

    - #### beginStructLayout

          public void beginStructLayout()
                                 throws Exception

      Description copied from interface: `GlueEmitter`
      Begins the process of computing field offsets and type sizes for the structs to be emitted.
      Specified by:
        `beginStructLayout` in interface `GlueEmitter`
      Throws:
        `Exception`

    - #### layoutStruct

          public void layoutStruct(CompoundType t)
                            throws Exception

      Description copied from interface: `GlueEmitter`
      Lays out one struct which will be emitted later.
      Specified by:
        `layoutStruct` in interface `GlueEmitter`
      Throws:
        `Exception`

    - #### endStructLayout

          public void endStructLayout()
                               throws Exception

      Description copied from interface: `GlueEmitter`
      Finishes the struct layout process.
      Specified by:
        `endStructLayout` in interface `GlueEmitter`
      Throws:
        `Exception`

    - #### beginStructs

          public void beginStructs(TypeDictionary typedefDictionary,
                          TypeDictionary structDictionary,
                          Map<Type,Type> canonMap)
                            throws Exception

      Specified by:
        `beginStructs` in interface `GlueEmitter`
      Throws:
        `Exception`

    - #### emitStruct

          public void emitStruct(CompoundType structCType,
                        String alternateName)
                          throws Exception

      Description copied from interface: `GlueEmitter`
      Emit glue code for the given CompoundType. alternateName is provided when the CompoundType (e.g. "struct foo_t") has not been typedefed to anything but the type of "pointer to struct foo_t" has (e.g. "typedef struct foo_t {} *Foo"); in this case alternateName would be set to Foo.
      Specified by:
        `emitStruct` in interface `GlueEmitter`
      Throws:
        `Exception`

    - #### endStructs

          public void endStructs()
                          throws Exception

      Specified by:
        `endStructs` in interface `GlueEmitter`
      Throws:
        `Exception`

    - #### addStrings2Buffer

          public static int addStrings2Buffer(StringBuilder buf,
                              String sep,
                              String first,
                              Collection<String> col)

    - #### openFile

          protected PrintWriter openFile(String filename,
                             String simpleClassName)
                                  throws IOException

      Parameters:
        `filename` - the class's full filename to open w/ write access
        `simpleClassName` - the simple class name, i.e. w/o package name
      Returns:
        a `PrintWriter` instance to write the class source file or `null` to suppress output!
      Throws:
        `IOException`

    - #### javaWriter

          protected PrintWriter javaWriter()

    - #### javaImplWriter

          protected PrintWriter javaImplWriter()

    - #### cWriter

          protected PrintWriter cWriter()

    - #### getJavaOutputDir

          protected String getJavaOutputDir()

      Returns the value that was specified by the configuration directive "JavaOutputDir", or the default if none was specified.

    - #### getJavaPackageName

          protected String getJavaPackageName()

      Returns the value that was specified by the configuration directive "Package", or the default if none was specified.

    - #### getImplPackageName

          protected String getImplPackageName()

      Returns the value that was specified by the configuration directive "ImplPackage", or the default if none was specified.

    - #### emitCustomJavaCode

          protected void emitCustomJavaCode(PrintWriter writer,
                                String className)
                                     throws Exception

      Emit all the strings specified in the "CustomJavaCode" parameters of the configuration file.
      Throws:
        `Exception`

    - #### emitAllFileHeaders

          protected void emitAllFileHeaders()
                                     throws IOException

      Write out any header information for the output files (class declaration and opening brace, import statements, etc).
      Throws:
        `IOException`

    - #### emitCHeader

          protected void emitCHeader(PrintWriter cWriter,
                         String packageName,
                         String className)

    - #### emitCInitCode

          protected void emitCInitCode(PrintWriter cWriter,
                           String packageName,
                           String className)

    - #### emitJavaInitCode

          protected void emitJavaInitCode(PrintWriter jWriter,
                              String className)

    - #### emitAllFileFooters

          protected void emitAllFileFooters()

      Write out any footer information for the output files (closing brace of class definition, etc).

    - #### expandMethodBinding

          protected List<MethodBinding> expandMethodBinding(MethodBinding binding)