Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 87d6313

Browse files
smowtonigfoo
authored andcommitted
Move extractClassInstance to the file extractor
Since now we know the file context has been set correctly at this point
1 parent c4d6321 commit 87d6313

1 file changed

Lines changed: 49 additions & 47 deletions

File tree

java/kotlin-extractor/src/main/kotlin/KotlinExtractorExtension.kt

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ val primitiveTypeMapping = mapOf(
306306

307307
open class KotlinUsesExtractor(
308308
open val logger: Logger,
309-
open val tw: FileTrapWriter,
309+
open val tw: TrapWriter,
310310
val dependencyCollector: TrapFileManager?,
311311
val externalClassExtractor: ExternalClassExtractor,
312312
val pluginContext: IrPluginContext) {
@@ -343,9 +343,9 @@ open class KotlinUsesExtractor(
343343
?.owner
344344

345345
/**
346-
* Gets a KotlinUsesExtractor like this one, except it attributes locations to the file that declares the given class.
346+
* Gets a KotlinFileExtractor based on this one, except it attributes locations to the file that declares the given class.
347347
*/
348-
fun withSourceFileOfClass(cls: IrClass, populateFileTables: Boolean): KotlinUsesExtractor {
348+
fun withSourceFileOfClass(cls: IrClass, populateFileTables: Boolean): KotlinFileExtractor {
349349
val clsFile = cls.fileOrNull
350350

351351
val newTrapWriter =
@@ -354,7 +354,9 @@ open class KotlinUsesExtractor(
354354
else
355355
tw.withTargetFile(clsFile.path, clsFile.fileEntry)
356356

357-
return KotlinUsesExtractor(logger, newTrapWriter, dependencyCollector, externalClassExtractor, pluginContext)
357+
val newLogger = FileLogger(logger.logCounter, newTrapWriter)
358+
359+
return KotlinFileExtractor(newLogger, newTrapWriter, dependencyCollector, externalClassExtractor, pluginContext)
358360
}
359361

360362
fun useClassInstance(c: IrClass, typeArgs: List<IrTypeArgument>): UseClassInstanceResult {
@@ -474,49 +476,6 @@ open class KotlinUsesExtractor(
474476
fun classShortName(c: IrClass, typeArgs: List<IrTypeArgument>) =
475477
"${c.name}${typeArgsShortName(typeArgs)}"
476478

477-
fun extractClassInstance(c: IrClass, typeArgs: List<IrTypeArgument>): Label<out DbClassorinterface> {
478-
if (typeArgs.isEmpty()) {
479-
logger.warn(Severity.ErrorSevere, "Instance without type arguments: " + c.name.asString())
480-
}
481-
482-
val id = addClassLabel(c, typeArgs)
483-
val pkg = c.packageFqName?.asString() ?: ""
484-
val cls = classShortName(c, typeArgs)
485-
val pkgId = extractPackage(pkg)
486-
if(c.kind == ClassKind.INTERFACE) {
487-
@Suppress("UNCHECKED_CAST")
488-
val interfaceId = id as Label<out DbInterface>
489-
@Suppress("UNCHECKED_CAST")
490-
val sourceInterfaceId = useClassSource(c) as Label<out DbInterface>
491-
tw.writeInterfaces(interfaceId, cls, pkgId, sourceInterfaceId)
492-
} else {
493-
@Suppress("UNCHECKED_CAST")
494-
val classId = id as Label<out DbClass>
495-
@Suppress("UNCHECKED_CAST")
496-
val sourceClassId = useClassSource(c) as Label<out DbClass>
497-
tw.writeClasses(classId, cls, pkgId, sourceClassId)
498-
499-
if (c.kind == ClassKind.ENUM_CLASS) {
500-
tw.writeIsEnumType(classId)
501-
}
502-
}
503-
504-
for ((idx, arg) in typeArgs.withIndex()) {
505-
val argId = getTypeArgumentLabel(arg)
506-
tw.writeTypeArgs(argId, idx, id)
507-
}
508-
tw.writeIsParameterized(id)
509-
val unbound = useClassSource(c)
510-
tw.writeErasure(id, unbound)
511-
extractClassModifiers(c, id)
512-
extractClassSupertypes(c, id)
513-
514-
val locId = tw.getLocation(c)
515-
tw.writeHasLocation(id, locId)
516-
517-
return id
518-
}
519-
520479
fun useSimpleTypeClass(c: IrClass, args: List<IrTypeArgument>, hasQuestionMark: Boolean): TypeResults {
521480
val classInstanceResult = useClassInstance(c, args)
522481
val javaClassId = classInstanceResult.classLabel
@@ -1092,6 +1051,49 @@ open class KotlinFileExtractor(
10921051
return id
10931052
}
10941053

1054+
fun extractClassInstance(c: IrClass, typeArgs: List<IrTypeArgument>): Label<out DbClassorinterface> {
1055+
if (typeArgs.isEmpty()) {
1056+
logger.warn(Severity.ErrorSevere, "Instance without type arguments: " + c.name.asString())
1057+
}
1058+
1059+
val id = addClassLabel(c, typeArgs)
1060+
val pkg = c.packageFqName?.asString() ?: ""
1061+
val cls = classShortName(c, typeArgs)
1062+
val pkgId = extractPackage(pkg)
1063+
if(c.kind == ClassKind.INTERFACE) {
1064+
@Suppress("UNCHECKED_CAST")
1065+
val interfaceId = id as Label<out DbInterface>
1066+
@Suppress("UNCHECKED_CAST")
1067+
val sourceInterfaceId = useClassSource(c) as Label<out DbInterface>
1068+
tw.writeInterfaces(interfaceId, cls, pkgId, sourceInterfaceId)
1069+
} else {
1070+
@Suppress("UNCHECKED_CAST")
1071+
val classId = id as Label<out DbClass>
1072+
@Suppress("UNCHECKED_CAST")
1073+
val sourceClassId = useClassSource(c) as Label<out DbClass>
1074+
tw.writeClasses(classId, cls, pkgId, sourceClassId)
1075+
1076+
if (c.kind == ClassKind.ENUM_CLASS) {
1077+
tw.writeIsEnumType(classId)
1078+
}
1079+
}
1080+
1081+
for ((idx, arg) in typeArgs.withIndex()) {
1082+
val argId = getTypeArgumentLabel(arg)
1083+
tw.writeTypeArgs(argId, idx, id)
1084+
}
1085+
tw.writeIsParameterized(id)
1086+
val unbound = useClassSource(c)
1087+
tw.writeErasure(id, unbound)
1088+
extractClassModifiers(c, id)
1089+
extractClassSupertypes(c, id)
1090+
1091+
val locId = tw.getLocation(c)
1092+
tw.writeHasLocation(id, locId)
1093+
1094+
return id
1095+
}
1096+
10951097
fun extractClassSource(c: IrClass): Label<out DbClassorinterface> {
10961098
val id = useClassSource(c)
10971099
val pkg = c.packageFqName?.asString() ?: ""

0 commit comments

Comments
 (0)