Interface ICompiler

    • Method Detail

      • setEncoding

        void setEncoding​(java.nio.charset.Charset encoding)
        The equivalent of JAVA's "-encoding" command line option.
        See Also:
        setSourceCharset(Charset)
      • setSourceCharset

        void setSourceCharset​(java.nio.charset.Charset charset)
        Same as setEncoding(Charset), but with a more precise name.
      • setDebugLines

        void setDebugLines​(boolean value)
        Equivalent of -g:lines.
      • setDebugVars

        void setDebugVars​(boolean value)
        Equivalent of -g:vars.
      • setDebugSource

        void setDebugSource​(boolean value)
        Equivalent of -g:source.
      • setSourceVersion

        void setSourceVersion​(int version)
        Specifies the version of source code accepted, in analogy with JAVAC's -source command line option. May be ignored by an implementation (e.g. the janino implementation always accepts the language features as described on the home page). Allowed values, and the default value, depend on the implementation. -1 means to use a default version.
      • setTargetVersion

        void setTargetVersion​(int version)
        Generates class files that target a specified release of the virtual machine, in analogy with JAVAC's -target command line option. Allowed values depend on the implementation. The default value also depends on the implementation. The only invariant is that the generated class files are suitable for the currently executing JVM. -1 means to use a default version.
      • setSourceFinder

        void setSourceFinder​(ResourceFinder sourceFinder)
        Finds more .java resources that need to be compiled, i.e. implements JAVAC's -sourcepath option.
      • setSourcePath

        void setSourcePath​(java.io.File[] directoriesAndArchives)
        Equivalent of --source-path.

        Equivalent with setSourceFinder(new PathResourceFinder(directoriesAndArchives)).

      • setBootClassPath

        void setBootClassPath​(java.io.File[] directoriesAndArchives)
        Equivalent of --boot-class-path.
      • setExtensionDirectories

        void setExtensionDirectories​(java.io.File[] directories)
        Equivalent of -extdirs.
      • setClassPath

        void setClassPath​(java.io.File[] directoriesAndArchives)
        Equivalent of --class-path.
      • setClassFileFinder

        void setClassFileFinder​(ResourceFinder classFileFinder,
                                boolean rebuild)
        Equivalent with setClassFileFinder(rebuild ? ResourceFinder.EMPTY_RESOURCE_FINDER : classFileFinder).
      • setVerbose

        void setVerbose​(boolean verbose)
        Equivalent of -verbose.
      • compile

        boolean compile​(java.io.File[] sourceFiles)
                 throws CompileException,
                        java.io.IOException
        Reads a set of Java compilation units (a.k.a. "source files") from the file system, compiles them into a set of "class files" and stores these in the file system. Additional source files are parsed and compiled on demand through the "source path" set of directories.

        For example, if the source path comprises the directories "A/B" and "../C", then the source file for class "com.acme.Main" is searched in

        A/B/com/acme/Main.java
        ../C/com/acme/Main.java

        Notice that it does make a difference whether you pass multiple source files to compile(File[]) or if you invoke compile(File[]) multiply: In the former case, the source files may contain arbitrary references among each other (even circular ones). In the latter case, only the source files on the source path may contain circular references, not the sourceFiles.

        This method must be called exactly once after object construction.

        Compile errors are reported as described at setCompileErrorHandler(ErrorHandler).

        Parameters:
        sourceFiles - Contain the compilation units to compile
        Returns:
        true for backwards compatibility (return value can safely be ignored)
        Throws:
        CompileException - Fatal compilation error, or the CompileException thrown be the installed compile error handler
        java.io.IOException - Occurred when reading from the sourceFiles
      • setCompileErrorHandler

        void setCompileErrorHandler​(@Nullable
                                    ErrorHandler errorHandler)
        Installs an ErrorHandler which is invoked during compilation on each error. (By default, the compilation throws a CompileException on the first error and terminates.)

        If the given ErrorHandler throws a CompileException, then the compilation terminates and the exception is propagated.

        If the given ErrorHandler does not throw a CompileException but completes normally, then the compilation may or may not continue, depending on the error. Iff the compilation of a compilation unit completes normally but errors were reported, then it will throw a CompileException indicating the number of errors.

        In other words: The ErrorHandler may throw a CompileException or not, but the compilation will definitely throw a CompileException if one or more compile errors have occurred.

        Parameters:
        errorHandler - null to restore the default behavior (throwing a CompileException)
      • setWarningHandler

        void setWarningHandler​(WarningHandler warningHandler)
        By default, warnings are discarded, but an application my install a custom WarningHandler.
        Parameters:
        warningHandler - null to indicate that no warnings be issued