Manual Java and Kotlin translation syntax

To translate Java or Kotlin code manually, include all source file on the command line and provide all of the dependencies via .jar files, .class files, or source files. Failing to provide dependencies may lead to suboptimal scan results. 

Kotlin to Java interoperability does not support Kotlin files provided by the –sourcepath option. For more information about the –sourcepath option, see Java Command-Line Options.

The basic command-line syntax to translate Java or Kotlin code is shown in the following example:

sourceanalyzer -b <build_id> -cp <classpath> [<translation_options>] <files> | <file_specifiers>

where:

  • <translation_options> are options passed to the compiler.
  • -cp <classpath> specifies the class path to use for resolving Java and Kotlin symbols.

    Include all JAR dependencies normally used to build the project. Separate multiple paths with semicolons (Windows) or colons (non-Windows).

    Similar to javac, OpenText SAST loads classes in the order they appear in the class path. If there are multiple classes with the same name in the list, OpenText SAST uses the first loaded class. In the following example, if both A.jar and B.jar include a class called MyData.class, OpenText SAST uses the MyData.class from A.jar.

    sourceanalyzer -cp A.jar:B.jar myfile.java

    OpenText strongly recommends that you avoid using duplicate classes with the -cp option.

    OpenText SAST loads JAR files in the following order:

    1. From the -cp option
    2. From jre/lib
    3. From <sast_install_dir>/Core/default_jars

    This enables you to override a library class by including the similarly-named class in a JAR specified with the -cp option.

For descriptions of all the available Java-specific command-line options, see "Java/J2EE Command-Line Options".

With Java code, OpenText SAST can additionally emulate the compiler to help integrate more easily into custom build scripts.

To have OpenText SAST emulate the compiler, type:

sourceanalyzer -b <build_id> javac [<translation_options>]