diff --git a/java/kotlin-extractor2/src/main/kotlin/KotlinExtractor.kt b/java/kotlin-extractor2/src/main/kotlin/KotlinExtractor.kt index 2d610fb1230..47df072415e 100644 --- a/java/kotlin-extractor2/src/main/kotlin/KotlinExtractor.kt +++ b/java/kotlin-extractor2/src/main/kotlin/KotlinExtractor.kt @@ -267,6 +267,9 @@ OLD: KE1 context (KaSession) fun dumpFunction(f: KtFunction) { + println("=== Have function") + println(f) + println(f.parent) val block = f.getBodyExpression() as KtBlockExpression for (p: KtExpression in block.getStatements()) { if (p is KtProperty) { @@ -473,6 +476,11 @@ OLD: KE1 } } } + if (c is KtFunction) { + if (c.name == "test") { + dumpFunction(c) + } + } val srcFilePath = srcFile.virtualFilePath val logger = FileLogger(loggerBase, fileDiagnosticTrapWriter) @@ -531,10 +539,7 @@ OLD: KE1 */ val fileExtractor = KotlinFileExtractor( -/* -OLD: KE1 logger, -*/ sftw, /* OLD: KE1 diff --git a/java/kotlin-extractor2/src/main/kotlin/KotlinFileExtractor.kt b/java/kotlin-extractor2/src/main/kotlin/KotlinFileExtractor.kt index f19908ff049..14af22b27b6 100644 --- a/java/kotlin-extractor2/src/main/kotlin/KotlinFileExtractor.kt +++ b/java/kotlin-extractor2/src/main/kotlin/KotlinFileExtractor.kt @@ -74,10 +74,7 @@ import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull */ open class KotlinFileExtractor( -/* -OLD: KE1 override val logger: FileLogger, -*/ override val tw: FileTrapWriter, /* OLD: KE1 @@ -92,10 +89,7 @@ OLD: KE1 */ ) : KotlinUsesExtractor( -/* -OLD: KE1 logger, -*/ tw, /* OLD: KE1 @@ -291,9 +285,12 @@ OLD: KE1 */ } is KtFunction -> { + println("=== Dec is fun") + println(declaration) + println(declaration.parent) + val parentId = useDeclarationParentOf(declaration, false)?.cast() /* OLD: KE1 - val parentId = useDeclarationParentOf(declaration, false)?.cast() if (parentId != null) { extractFunction( declaration, diff --git a/java/kotlin-extractor2/src/main/kotlin/KotlinUsesExtractor.kt b/java/kotlin-extractor2/src/main/kotlin/KotlinUsesExtractor.kt index b437eead955..71bb582f239 100644 --- a/java/kotlin-extractor2/src/main/kotlin/KotlinUsesExtractor.kt +++ b/java/kotlin-extractor2/src/main/kotlin/KotlinUsesExtractor.kt @@ -1,5 +1,8 @@ package com.github.codeql +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.psi.* + /* OLD: KE1 import com.github.codeql.utils.* @@ -31,10 +34,7 @@ import org.jetbrains.kotlin.util.OperatorNameConventions */ open class KotlinUsesExtractor( -/* -OLD: KE1 open val logger: Logger, -*/ open val tw: TrapWriter, /* OLD: KE1 @@ -950,27 +950,36 @@ OLD: KE1 } } } +*/ - private fun parentOf(d: IrDeclaration): IrDeclarationParent { + private fun parentOf(d: KtDeclaration): PsiElement { +/* +OLD: KE1 if (d is IrField) { return getFieldParent(d) } +*/ return d.parent } fun useDeclarationParentOf( // The declaration - d: IrDeclaration, + d: KtDeclaration, // Whether the type of entity whose parent this is can be a // top-level entity in the JVM's eyes. If so, then its parent may - // be a file; otherwise, if dp is a file foo.kt, then the parent - // is really the JVM class FooKt. + // be a file; otherwise, if the parent appears to be a file foo.kt, + // then the parent is really the JVM class FooKt. canBeTopLevel: Boolean, +/* +OLD: KE1 classTypeArguments: List? = null, inReceiverContext: Boolean = false +*/ ): Label? { val parent = parentOf(d) +/* +OLD: KE1 if (parent is IrExternalPackageFragment) { // This is in a file class. val fqName = getFileClassFqName(d) @@ -982,24 +991,33 @@ OLD: KE1 } return extractFileClass(fqName) } - return useDeclarationParent(parent, canBeTopLevel, classTypeArguments, inReceiverContext) +*/ + return useDeclarationParent(parent, canBeTopLevel /* TODO , classTypeArguments, inReceiverContext */) } +/* +OLD: KE1 // Generally, useDeclarationParentOf should be used instead of // calling this directly, as this cannot handle // IrExternalPackageFragment +*/ fun useDeclarationParent( // The declaration parent according to Kotlin - dp: IrDeclarationParent, + dp: PsiElement, // Whether the type of entity whose parent this is can be a // top-level entity in the JVM's eyes. If so, then its parent may // be a file; otherwise, if dp is a file foo.kt, then the parent // is really the JVM class FooKt. canBeTopLevel: Boolean, +/* +OLD: KE1 classTypeArguments: List? = null, inReceiverContext: Boolean = false +*/ ): Label? = when (dp) { +/* +OLD: KE1 is IrFile -> if (canBeTopLevel) { usePackage(dp.packageFqName.asString()) @@ -1024,12 +1042,15 @@ OLD: KE1 logger.error("Unable to handle IrExternalPackageFragment as an IrDeclarationParent") null } +*/ else -> { - logger.error("Unrecognised IrDeclarationParent: " + dp.javaClass) + logger.error("Unexpected declaration parent type: " + dp.javaClass) null } } +/* +OLD: KE1 private val IrDeclaration.isAnonymousFunction get() = this is IrSimpleFunction && name == SpecialNames.NO_NAME_PROVIDED