or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

compilation-services.mddaemon-connection.mdindex.mdrepl-client.mdservice-facades.mdstream-servers.md

service-facades.mddocs/

0

# Service Facades

1

2

Server implementations for handling compiler callbacks, incremental compilation services, and communication with the daemon process. These facades provide RMI-based services that bridge between client and daemon processes.

3

4

## Capabilities

5

6

### BasicCompilerServicesWithResultsFacadeServer

7

8

Basic implementation of compiler services facade for handling compilation messages and results.

9

10

```kotlin { .api }

11

/**

12

* Basic compiler services facade server for message handling

13

* @param messageCollector Handles compiler messages and diagnostics

14

* @param outputsCollector Optional callback for tracking output files

15

* @param port RMI port for service communication

16

*/

17

class BasicCompilerServicesWithResultsFacadeServer(

18

val messageCollector: MessageCollector,

19

val outputsCollector: ((File, List<File>) -> Unit)? = null,

20

port: Int = SOCKET_ANY_FREE_PORT

21

) : CompilerServicesFacadeBase, UnicastRemoteObject(

22

port,

23

LoopbackNetworkInterface.clientLoopbackSocketFactory,

24

LoopbackNetworkInterface.serverLoopbackSocketFactory

25

)

26

```

27

28

#### Message Reporting

29

30

```kotlin { .api }

31

/**

32

* Report compilation messages from daemon to client

33

* @param category Message category (compiler, daemon, exception, etc.)

34

* @param severity Message severity level

35

* @param message Message text content

36

* @param attachment Optional message attachment (e.g., source location)

37

*/

38

override fun report(category: Int, severity: Int, message: String?, attachment: Serializable?)

39

```

40

41

**Usage Example:**

42

43

```kotlin

44

import org.jetbrains.kotlin.daemon.client.BasicCompilerServicesWithResultsFacadeServer

45

import org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector

46

import java.io.File

47

48

val messageCollector = PrintingMessageCollector(System.out, null, false)

49

50

val outputsCollector = { outputFile: File, sourceFiles: List<File> ->

51

println("Generated: $outputFile")

52

println("From sources: ${sourceFiles.joinToString { it.name }}")

53

}

54

55

val servicesFacade = BasicCompilerServicesWithResultsFacadeServer(

56

messageCollector = messageCollector,

57

outputsCollector = outputsCollector,

58

port = 0 // Use any free port

59

)

60

61

// Use with compilation

62

val exitCode = KotlinCompilerClient.compile(

63

compilerService = compileService,

64

sessionId = sessionId,

65

targetPlatform = CompileService.TargetPlatform.JVM,

66

args = compilationArgs,

67

messageCollector = messageCollector,

68

outputsCollector = outputsCollector

69

)

70

```

71

72

### CompilerCallbackServicesFacadeServer

73

74

Comprehensive server implementation for compiler callback services supporting incremental compilation.

75

76

```kotlin { .api }

77

/**

78

* Compiler callback services facade server with incremental compilation support

79

* @param incrementalCompilationComponents Components for incremental compilation

80

* @param lookupTracker Tracks symbol lookups for incremental builds

81

* @param compilationCanceledStatus Allows checking compilation cancellation

82

* @param expectActualTracker Tracks expect/actual declarations

83

* @param inlineConstTracker Tracks inline constant usage

84

* @param enumWhenTracker Tracks enum when expression usage

85

* @param importTracker Tracks import usage

86

* @param incrementalResultsConsumer Consumes incremental compilation results

87

* @param incrementalDataProvider Provides incremental compilation data

88

* @param port RMI port for service communication

89

*/

90

class CompilerCallbackServicesFacadeServer(

91

val incrementalCompilationComponents: IncrementalCompilationComponents? = null,

92

val lookupTracker: LookupTracker? = null,

93

val compilationCanceledStatus: CompilationCanceledStatus? = null,

94

val expectActualTracker: ExpectActualTracker? = null,

95

val inlineConstTracker: InlineConstTracker? = null,

96

val enumWhenTracker: EnumWhenTracker? = null,

97

val importTracker: ImportTracker? = null,

98

val incrementalResultsConsumer: IncrementalResultsConsumer? = null,

99

val incrementalDataProvider: IncrementalDataProvider? = null,

100

port: Int = SOCKET_ANY_FREE_PORT

101

) : CompilerCallbackServicesFacade, UnicastRemoteObject(...)

102

```

103

104

#### Service Availability Checks

105

106

```kotlin { .api }

107

/**

108

* Check if incremental caches are available

109

* @return true if incremental compilation components are configured

110

*/

111

fun hasIncrementalCaches(): Boolean

112

113

/**

114

* Check if lookup tracker is available

115

* @return true if lookup tracker is configured

116

*/

117

fun hasLookupTracker(): Boolean

118

119

/**

120

* Check if compilation canceled status is available

121

* @return true if cancellation status checker is configured

122

*/

123

fun hasCompilationCanceledStatus(): Boolean

124

125

/**

126

* Check if expect/actual tracker is available

127

* @return true if expect/actual tracker is configured

128

*/

129

fun hasExpectActualTracker(): Boolean

130

131

/**

132

* Check if inline constant tracker is available

133

* @return true if inline constant tracker is configured

134

*/

135

fun hasInlineConstTracker(): Boolean

136

137

/**

138

* Check if enum when tracker is available

139

* @return true if enum when tracker is configured

140

*/

141

fun hasEnumWhenTracker(): Boolean

142

143

/**

144

* Check if import tracker is available

145

* @return true if import tracker is configured

146

*/

147

fun hasImportTracker(): Boolean

148

149

/**

150

* Check if incremental results consumer is available

151

* @return true if results consumer is configured

152

*/

153

fun hasIncrementalResultsConsumer(): Boolean

154

155

/**

156

* Check if incremental data provider is available

157

* @return true if data provider is configured

158

*/

159

fun hasIncrementalDataProvider(): Boolean

160

```

161

162

#### Incremental Cache Operations

163

164

```kotlin { .api }

165

/**

166

* Get obsolete package parts for incremental compilation

167

* @param target Target identifier for the compilation target

168

* @return Collection of obsolete package part names

169

*/

170

fun incrementalCache_getObsoletePackageParts(target: TargetId): Collection<String>

171

172

/**

173

* Get obsolete multifile class facades

174

* @param target Target identifier

175

* @return Collection of obsolete multifile class names

176

*/

177

fun incrementalCache_getObsoleteMultifileClassFacades(target: TargetId): Collection<String>

178

179

/**

180

* Get multifile facade parts

181

* @param target Target identifier

182

* @param internalName Internal name of the multifile facade

183

* @return Collection of facade part names or null

184

*/

185

fun incrementalCache_getMultifileFacadeParts(target: TargetId, internalName: String): Collection<String>?

186

187

/**

188

* Get package part data

189

* @param target Target identifier

190

* @param partInternalName Internal name of the package part

191

* @return Package part proto data or null

192

*/

193

fun incrementalCache_getPackagePartData(target: TargetId, partInternalName: String): JvmPackagePartProto?

194

195

/**

196

* Get module mapping data

197

* @param target Target identifier

198

* @return Module mapping data as byte array or null

199

*/

200

fun incrementalCache_getModuleMappingData(target: TargetId): ByteArray?

201

202

/**

203

* Get class file path

204

* @param target Target identifier

205

* @param internalClassName Internal class name

206

* @return Path to the class file

207

*/

208

fun incrementalCache_getClassFilePath(target: TargetId, internalClassName: String): String

209

210

/**

211

* Close incremental cache for target

212

* @param target Target identifier

213

*/

214

fun incrementalCache_close(target: TargetId)

215

```

216

217

#### Lookup Tracking

218

219

```kotlin { .api }

220

/**

221

* Check if lookup tracker requires position information

222

* @return true if position tracking is required

223

*/

224

fun lookupTracker_requiresPosition(): Boolean

225

226

/**

227

* Record lookup information for incremental compilation

228

* @param lookups Collection of lookup information to record

229

*/

230

fun lookupTracker_record(lookups: Collection<LookupInfo>)

231

232

/**

233

* Check if lookup tracker is a no-op implementation

234

* @return true if this is a do-nothing tracker

235

*/

236

fun lookupTracker_isDoNothing(): Boolean

237

```

238

239

#### Compilation Status Checking

240

241

```kotlin { .api }

242

/**

243

* Check if compilation has been canceled

244

* @return null if not canceled, throws exception if canceled

245

*/

246

fun compilationCanceledStatus_checkCanceled(): Void?

247

```

248

249

#### Tracking Operations

250

251

```kotlin { .api }

252

/**

253

* Report expect/actual declaration relationship

254

* @param expectedFilePath Path to expect declaration file

255

* @param actualFilePath Path to actual declaration file

256

*/

257

fun expectActualTracker_report(expectedFilePath: String, actualFilePath: String)

258

259

/**

260

* Report expect declaration of lenient stub

261

* @param expectedFilePath Path to expect declaration file

262

*/

263

fun expectActualTracker_reportExpectOfLenientStub(expectedFilePath: String)

264

265

/**

266

* Report inline constant usage

267

* @param filePath File path where constant is used

268

* @param owner Owner class of the constant

269

* @param name Constant name

270

* @param constType Constant type

271

*/

272

fun inlineConstTracker_report(filePath: String, owner: String, name: String, constType: String)

273

274

/**

275

* Report enum when expression usage

276

* @param whenUsageClassPath Class path where when is used

277

* @param enumClassFqName Fully qualified enum class name

278

*/

279

fun enumWhenTracker_report(whenUsageClassPath: String, enumClassFqName: String)

280

281

/**

282

* Report import usage

283

* @param filePath File path where import is used

284

* @param importedFqName Fully qualified name of imported symbol

285

*/

286

fun importTracker_report(filePath: String, importedFqName: String)

287

```

288

289

## Extension Functions

290

291

### MessageCollector Extensions

292

293

Extension function for handling daemon messages.

294

295

```kotlin { .api }

296

/**

297

* Report message from daemon to message collector

298

* @param outputsCollector Optional outputs collector callback

299

* @param category Message category code

300

* @param severity Message severity code

301

* @param message Message text

302

* @param attachment Optional message attachment

303

*/

304

fun MessageCollector.reportFromDaemon(

305

outputsCollector: ((File, List<File>) -> Unit)?,

306

category: Int,

307

severity: Int,

308

message: String?,

309

attachment: Serializable?

310

)

311

```

312

313

## Usage Patterns

314

315

### Basic Services Facade

316

317

```kotlin

318

import org.jetbrains.kotlin.daemon.client.BasicCompilerServicesWithResultsFacadeServer

319

import org.jetbrains.kotlin.cli.common.messages.MessageCollector

320

321

class MyMessageCollector : MessageCollector {

322

private val messages = mutableListOf<String>()

323

324

override fun report(

325

severity: CompilerMessageSeverity,

326

message: String,

327

location: CompilerMessageSourceLocation?

328

) {

329

val locationStr = location?.let { "${it.path}:${it.line}" } ?: ""

330

messages.add("$severity: $locationStr: $message")

331

println("$severity: $locationStr: $message")

332

}

333

334

override fun hasErrors(): Boolean =

335

messages.any { it.startsWith("ERROR") }

336

337

override fun clear() = messages.clear()

338

339

fun getAllMessages(): List<String> = messages.toList()

340

}

341

342

val messageCollector = MyMessageCollector()

343

val servicesFacade = BasicCompilerServicesWithResultsFacadeServer(

344

messageCollector = messageCollector,

345

outputsCollector = null

346

)

347

348

// Use in compilation...

349

```

350

351

### Incremental Compilation Services

352

353

```kotlin

354

import org.jetbrains.kotlin.daemon.client.CompilerCallbackServicesFacadeServer

355

import org.jetbrains.kotlin.incremental.components.LookupTracker

356

357

class MyLookupTracker : LookupTracker {

358

private val lookups = mutableListOf<String>()

359

360

override val requiresPosition: Boolean = true

361

362

override fun record(

363

filePath: String,

364

position: Int,

365

scopeFqName: String,

366

scopeKind: ScopeKind,

367

name: String

368

) {

369

lookups.add("$filePath:$position -> $scopeFqName.$name")

370

println("Lookup: $filePath:$position -> $scopeFqName.$name")

371

}

372

373

fun getLookups(): List<String> = lookups.toList()

374

}

375

376

val lookupTracker = MyLookupTracker()

377

val incrementalComponents = MyIncrementalCompilationComponents()

378

379

val callbacksFacade = CompilerCallbackServicesFacadeServer(

380

incrementalCompilationComponents = incrementalComponents,

381

lookupTracker = lookupTracker,

382

compilationCanceledStatus = null

383

)

384

385

// Check service availability

386

if (callbacksFacade.hasLookupTracker()) {

387

println("Lookup tracking enabled")

388

}

389

390

if (callbacksFacade.hasIncrementalCaches()) {

391

println("Incremental compilation enabled")

392

}

393

```

394

395

### Complete Services Setup

396

397

```kotlin

398

val messageCollector = PrintingMessageCollector(System.out, null, true)

399

400

val outputsCollector = { outputFile: File, sourceFiles: List<File> ->

401

println("Compiled ${sourceFiles.size} files to $outputFile")

402

}

403

404

val basicServices = BasicCompilerServicesWithResultsFacadeServer(

405

messageCollector = messageCollector,

406

outputsCollector = outputsCollector

407

)

408

409

val callbackServices = CompilerCallbackServicesFacadeServer(

410

incrementalCompilationComponents = myIncrementalComponents,

411

lookupTracker = myLookupTracker,

412

compilationCanceledStatus = myCancellationStatus

413

)

414

415

// Services are now ready for daemon compilation

416

val compilationResult = compileService.compile(

417

sessionId,

418

args,

419

compilationOptions,

420

basicServices,

421

callbackServices

422

)

423

```