Class SequenceCompiler

    • Field Detail

      • debugCompilationFailure

        private static final String debugCompilationFailure
        If non-null, do verbose output for compilation failures where the Java source code contains the string.
      • compilerOptions

        private final List<String> compilerOptions
        The options to the compiler.
      • compiler

        private final JavaCompiler compiler
        The Java compiler.
      • fileManager

        private final JavaFileManager fileManager
        The FileManager for this compiler.
    • Constructor Detail

      • SequenceCompiler

        public SequenceCompiler​(List<String> compilerOptions)
        Creates a SequenceCompiler.
        Parameters:
        compilerOptions - the compiler options
    • Method Detail

      • isCompilable

        public boolean isCompilable​(String packageName,
                                    String classname,
                                    String javaSource)
        Indicates whether the given class is compilable.
        Parameters:
        packageName - the package name for the class, null if default package
        classname - the simple name of the class
        javaSource - the source text of the class
        Returns:
        true if class source was successfully compiled, false otherwise
      • compile

        private void compile​(String packageName,
                             String classname,
                             String javaSource)
                      throws SequenceCompilerException
        Compiles the given class. If this method returns normally, compilation was successful.
        Parameters:
        packageName - the package of the class, null if default package
        classname - the simple name of the class
        javaSource - the source text of the class
        Throws:
        SequenceCompilerException - if the compilation fails
      • compile

        private boolean compile​(String packageName,
                                String classname,
                                String javaSource,
                                DiagnosticCollector<JavaFileObject> diagnostics)
        A helper method for the compile(String, String, String) and isCompilable(String, String, String) methods: compiles the given class using the given diagnostics collector.
        Parameters:
        packageName - the package of the class, null if default package
        classname - the simple name of the class
        javaSource - the source text of the class
        diagnostics - the DiagnosticsCollector object to use for the compilation. Always use a new diagnostics collector each compilation to avoid accumulating errors.
        Returns:
        true if the class source is successfully compiled, false otherwise
      • compileAndLoad

        public Class<?> compileAndLoad​(@DotSeparatedIdentifiers String packageName,
                                       @BinaryNameWithoutPackage String classname,
                                       String javaSource)
                                throws SequenceCompilerException
        Compiles the given class, leads it, and returns the Class object. If this method returns normally, compilation was successful.
        Parameters:
        packageName - the package of the class, null if default package
        classname - the simple name of the class
        javaSource - the source text of the class
        Returns:
        the loaded Class object
        Throws:
        SequenceCompilerException - if the compilation fails
      • loadClassFile

        private static Class<?> loadClassFile​(File directory,
                                              @BinaryName String className)
        Given a .class file, returns the corresponding Class object.
        Parameters:
        directory - the directory containing the .class file (possibly in a package-named subdirectory)
        className - the binary name of the class defined in the file
        Returns:
        the loaded Class object
      • fullyQualifiedName

        @BinaryName String fullyQualifiedName​(@DotSeparatedIdentifiers String packageName,
                                              @BinaryNameWithoutPackage String classname)
        Constructs a fully-qualified class name from the given package and unqualified class name.
        Parameters:
        packageName - the package of the class, null if default package
        classname - the name of the class, without the package
        Returns:
        the fully-qualified class name constructed from the arguments