@@ -8,6 +8,7 @@ import java.nio.file.Files
8
8
import java.nio.file.Paths
9
9
import java.text.SimpleDateFormat
10
10
import java.util.Date
11
+ import java.util.Optional
11
12
import kotlin.system.exitProcess
12
13
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
13
14
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
@@ -167,8 +168,8 @@ fun doFile(logger: Logger, trapDir: File, srcDir: File, declaration: IrFile) {
167
168
val tw = TrapWriter (fileLabel, trapFileBW, declaration.fileEntry)
168
169
val id: Label <DbFile > = tw.getLabelFor(fileLabel)
169
170
tw.writeFiles(id, filePath, basename, extension, 0 )
170
- val fileExtractor = KotlinFileExtractor (logger, tw)
171
- fileExtractor.extractFile(id, declaration )
171
+ val fileExtractor = KotlinFileExtractor (logger, tw, declaration )
172
+ fileExtractor.extractFile(id)
172
173
}
173
174
}
174
175
@@ -179,14 +180,16 @@ fun <T> fakeLabel(): Label<T> {
179
180
return Label (0 )
180
181
}
181
182
182
- class KotlinFileExtractor (val logger : Logger , val tw : TrapWriter ) {
183
- fun extractFile (id : Label <DbFile >, f : IrFile ) {
184
- val pkg = f.fqName.asString()
183
+ class KotlinFileExtractor (val logger : Logger , val tw : TrapWriter , val file : IrFile ) {
184
+ val fileClass by lazy {
185
+ extractFileClass(file)
186
+ }
187
+
188
+ fun extractFile (id : Label <DbFile >) {
189
+ val pkg = file.fqName.asString()
185
190
val pkgId = extractPackage(pkg)
186
191
tw.writeCupackage(id, pkgId)
187
- // TODO: This shouldn't really exist if there is nothing to go on it
188
- val fileClass = extractFileClass(f)
189
- f.declarations.map { extractDeclaration(it, fileClass) }
192
+ file.declarations.map { extractDeclaration(it, Optional .empty()) }
190
193
}
191
194
192
195
fun extractFileClass (f : IrFile ): Label <out DbClass > {
@@ -233,11 +236,11 @@ class KotlinFileExtractor(val logger: Logger, val tw: TrapWriter) {
233
236
return id
234
237
}
235
238
236
- fun extractDeclaration (declaration : IrDeclaration , parentid : Label <out DbReftype >) {
239
+ fun extractDeclaration (declaration : IrDeclaration , optParentid : Optional < Label <out DbReftype > >) {
237
240
when (declaration) {
238
241
is IrClass -> extractClass(declaration)
239
- is IrFunction -> extractFunction(declaration, parentid )
240
- is IrProperty -> extractProperty(declaration, parentid )
242
+ is IrFunction -> extractFunction(declaration, if (optParentid.isPresent()) optParentid.get() else fileClass )
243
+ is IrProperty -> extractProperty(declaration, if (optParentid.isPresent()) optParentid.get() else fileClass )
241
244
else -> logger.warn(" Unrecognised IrDeclaration: " + declaration.javaClass)
242
245
}
243
246
}
@@ -309,7 +312,7 @@ class KotlinFileExtractor(val logger: Logger, val tw: TrapWriter) {
309
312
val pkgId = extractPackage(pkg)
310
313
tw.writeClasses(id, cls, pkgId, id)
311
314
tw.writeHasLocation(id, locId)
312
- c.declarations.map { extractDeclaration(it, id ) }
315
+ c.declarations.map { extractDeclaration(it, Optional .of(id) ) }
313
316
return id
314
317
}
315
318
0 commit comments