mirror of
https://github.com/github/codeql.git
synced 2026-06-06 05:57:07 +02:00
Kotlin 2.4.0: Use IrAnnotationImpl for annotation creation
In 2.4.0, annotation lists are typed as List<IrAnnotation> and IrConstructorCallImpl does not extend IrAnnotation. Replace all IrConstructorCallImpl.fromSymbolOwner() calls that create annotations with a compat wrapper codeQlAnnotationFromSymbolOwner() that uses IrAnnotationImpl.fromSymbolOwner() in 2.4.0 (returning proper IrAnnotation instances) and IrConstructorCallImpl.fromSymbolOwner() in pre-2.4.0 versions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -721,7 +721,7 @@ open class KotlinFileExtractor(
|
||||
(it.type as? IrSimpleType)?.classFqName?.asString() != "kotlin.Deprecated"
|
||||
} +
|
||||
// Note we lose any arguments to @java.lang.Deprecated that were written in source.
|
||||
IrConstructorCallImpl.fromSymbolOwner(
|
||||
codeQlAnnotationFromSymbolOwner(
|
||||
UNDEFINED_OFFSET,
|
||||
UNDEFINED_OFFSET,
|
||||
jldConstructor.returnType,
|
||||
@@ -2327,7 +2327,7 @@ open class KotlinFileExtractor(
|
||||
getClassByFqName(pluginContext, it)?.let { annotationClass ->
|
||||
annotationClass.owner.declarations.firstIsInstanceOrNull<IrConstructor>()?.let {
|
||||
annotationConstructor ->
|
||||
IrConstructorCallImpl.fromSymbolOwner(
|
||||
codeQlAnnotationFromSymbolOwner(
|
||||
UNDEFINED_OFFSET,
|
||||
UNDEFINED_OFFSET,
|
||||
annotationConstructor.returnType,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.github.codeql
|
||||
|
||||
import com.github.codeql.utils.versions.codeQlAnnotationFromSymbolOwner
|
||||
import com.github.codeql.utils.versions.codeQlGetValueArgument
|
||||
import com.github.codeql.utils.versions.codeQlPutValueArgument
|
||||
import com.github.codeql.utils.versions.codeQlSetAnnotations
|
||||
@@ -121,7 +122,7 @@ class MetaAnnotationSupport(
|
||||
)
|
||||
return null
|
||||
} else {
|
||||
return IrConstructorCallImpl.fromSymbolOwner(
|
||||
return codeQlAnnotationFromSymbolOwner(
|
||||
containerClass.defaultType,
|
||||
containerConstructor.symbol
|
||||
)
|
||||
@@ -234,7 +235,7 @@ class MetaAnnotationSupport(
|
||||
)
|
||||
}
|
||||
|
||||
return IrConstructorCallImpl.fromSymbolOwner(
|
||||
return codeQlAnnotationFromSymbolOwner(
|
||||
UNDEFINED_OFFSET,
|
||||
UNDEFINED_OFFSET,
|
||||
targetConstructor.returnType,
|
||||
@@ -287,7 +288,7 @@ class MetaAnnotationSupport(
|
||||
val targetConstructor =
|
||||
retentionType.declarations.firstIsInstanceOrNull<IrConstructor>() ?: return null
|
||||
|
||||
return IrConstructorCallImpl.fromSymbolOwner(
|
||||
return codeQlAnnotationFromSymbolOwner(
|
||||
UNDEFINED_OFFSET,
|
||||
UNDEFINED_OFFSET,
|
||||
targetConstructor.returnType,
|
||||
@@ -419,7 +420,7 @@ class MetaAnnotationSupport(
|
||||
.map { it.deepCopyWithSymbols(containerClass) } +
|
||||
listOfNotNull(
|
||||
repeatableContainerAnnotation?.let {
|
||||
IrConstructorCallImpl.fromSymbolOwner(
|
||||
codeQlAnnotationFromSymbolOwner(
|
||||
UNDEFINED_OFFSET,
|
||||
UNDEFINED_OFFSET,
|
||||
it.returnType,
|
||||
@@ -467,7 +468,7 @@ class MetaAnnotationSupport(
|
||||
containerClass.symbol,
|
||||
containerClass.defaultType
|
||||
)
|
||||
return IrConstructorCallImpl.fromSymbolOwner(
|
||||
return codeQlAnnotationFromSymbolOwner(
|
||||
UNDEFINED_OFFSET,
|
||||
UNDEFINED_OFFSET,
|
||||
repeatableConstructor.returnType,
|
||||
@@ -493,7 +494,7 @@ class MetaAnnotationSupport(
|
||||
javaAnnotationDocumented?.declarations?.firstIsInstanceOrNull<IrConstructor>()
|
||||
?: return null
|
||||
|
||||
return IrConstructorCallImpl.fromSymbolOwner(
|
||||
return codeQlAnnotationFromSymbolOwner(
|
||||
UNDEFINED_OFFSET,
|
||||
UNDEFINED_OFFSET,
|
||||
documentedConstructor.returnType,
|
||||
|
||||
@@ -192,7 +192,7 @@ object RawTypeAnnotation {
|
||||
addConstructor { isPrimary = true }
|
||||
}
|
||||
val constructor = annoClass.constructors.single()
|
||||
IrConstructorCallImpl.fromSymbolOwner(constructor.constructedClassType, constructor.symbol)
|
||||
codeQlAnnotationFromSymbolOwner(constructor.constructedClassType, constructor.symbol)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ import org.jetbrains.kotlin.ir.declarations.IrValueParameter
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.addAnnotations
|
||||
|
||||
@@ -58,3 +60,12 @@ fun codeQlSetAnnotations(container: org.jetbrains.kotlin.ir.declarations.IrMutab
|
||||
fun IrFunction.codeQlSetDispatchReceiverParameter(param: IrValueParameter?) {
|
||||
dispatchReceiverParameter = param
|
||||
}
|
||||
|
||||
// In pre-2.4.0, annotations are List<IrConstructorCall> so IrConstructorCallImpl works directly.
|
||||
fun codeQlAnnotationFromSymbolOwner(
|
||||
startOffset: Int, endOffset: Int, type: IrType, symbol: IrConstructorSymbol, typeArgumentsCount: Int
|
||||
): IrConstructorCall =
|
||||
IrConstructorCallImpl.fromSymbolOwner(startOffset, endOffset, type, symbol, typeArgumentsCount)
|
||||
|
||||
fun codeQlAnnotationFromSymbolOwner(type: IrType, symbol: IrConstructorSymbol): IrConstructorCall =
|
||||
IrConstructorCallImpl.fromSymbolOwner(type, symbol)
|
||||
|
||||
@@ -8,6 +8,9 @@ import org.jetbrains.kotlin.ir.expressions.IrAnnotation
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrAnnotationImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.fromSymbolOwner
|
||||
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.addAnnotations
|
||||
|
||||
@@ -93,3 +96,13 @@ fun IrFunction.codeQlSetDispatchReceiverParameter(param: IrValueParameter?) {
|
||||
parameters = mutableParams
|
||||
}
|
||||
|
||||
// In 2.4.0, annotation lists require IrAnnotation instances.
|
||||
// Use IrAnnotationImpl.fromSymbolOwner instead of IrConstructorCallImpl.fromSymbolOwner.
|
||||
fun codeQlAnnotationFromSymbolOwner(
|
||||
startOffset: Int, endOffset: Int, type: IrType, symbol: IrConstructorSymbol, typeArgumentsCount: Int
|
||||
): IrConstructorCall =
|
||||
IrAnnotationImpl.fromSymbolOwner(startOffset, endOffset, type, symbol, typeArgumentsCount)
|
||||
|
||||
fun codeQlAnnotationFromSymbolOwner(type: IrType, symbol: IrConstructorSymbol): IrConstructorCall =
|
||||
IrAnnotationImpl.fromSymbolOwner(type, symbol)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user