| 42 | import {JavaCompiler} from './java.js'; |
| 43 | |
| 44 | export class KotlinCompiler extends JavaCompiler implements SimpleOutputFilenameCompiler { |
| 45 | static override get key() { |
| 46 | return 'kotlin'; |
| 47 | } |
| 48 | |
| 49 | javaHome: string; |
| 50 | |
| 51 | constructor(compilerInfo: PreliminaryCompilerInfo, env: CompilationEnvironment) { |
| 52 | super(compilerInfo, env); |
| 53 | this.javaHome = this.compilerProps<string>(`compiler.${this.compiler.id}.java_home`); |
| 54 | } |
| 55 | |
| 56 | override async runCompiler( |
| 57 | compiler: string, |
| 58 | options: string[], |
| 59 | inputFilename: string, |
| 60 | execOptions: ExecutionOptionsWithEnv, |
| 61 | filters?: ParseFiltersAndOutputOptions, |
| 62 | ): Promise<CompilationResult> { |
| 63 | if (!execOptions) { |
| 64 | execOptions = this.getDefaultExecOptions(); |
| 65 | } |
| 66 | if (!execOptions.customCwd) { |
| 67 | execOptions.customCwd = path.dirname(inputFilename); |
| 68 | } |
| 69 | // The items in 'options' before the source file are user inputs. |
| 70 | const sourceFileOptionIndex = options.findIndex(option => { |
| 71 | return option.endsWith('.kt'); |
| 72 | }); |
| 73 | const userOptions = options.slice(0, sourceFileOptionIndex); |
| 74 | const kotlinOptions = _.compact([...this.getClasspathArgument(), ...userOptions, inputFilename]); |
| 75 | const result = await this.exec(compiler, kotlinOptions, execOptions); |
| 76 | return { |
| 77 | ...this.transformToCompilationResult(result, inputFilename), |
| 78 | languageId: this.getCompilerResultLanguageId(filters), |
| 79 | instructionSet: this.getInstructionSetFromCompilerArgs(options), |
| 80 | }; |
| 81 | } |
| 82 | |
| 83 | override getDefaultExecOptions() { |
| 84 | const execOptions = super.getDefaultExecOptions(); |
| 85 | if (this.javaHome) { |
| 86 | execOptions.env.JAVA_HOME = this.javaHome; |
| 87 | } |
| 88 | |
| 89 | return execOptions; |
| 90 | } |
| 91 | |
| 92 | override async getMainClassName() { |
| 93 | return 'ExampleKt'; |
| 94 | } |
| 95 | |
| 96 | override filterUserOptions(userOptions: string[]) { |
| 97 | // filter options without extra arguments |
| 98 | userOptions = (userOptions || []).filter( |
| 99 | option => option !== '-script' && option !== '-progressive' && !option.startsWith('-Xjavac'), |
| 100 | ); |
| 101 |
nothing calls this directly
no outgoing calls
no test coverage detected