mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
Replace uses of !! operator
This commit is contained in:
@@ -512,18 +512,24 @@ open class KotlinFileExtractor(
|
|||||||
annotationClass: IrClass,
|
annotationClass: IrClass,
|
||||||
containerClass: IrClass,
|
containerClass: IrClass,
|
||||||
entries: List<IrConstructorCall>,
|
entries: List<IrConstructorCall>,
|
||||||
): IrConstructorCall {
|
): IrConstructorCall? {
|
||||||
val annotationType = annotationClass.typeWith()
|
val annotationType = annotationClass.typeWith()
|
||||||
return IrConstructorCallImpl.fromSymbolOwner(containerClass.defaultType, containerClass.primaryConstructor!!.symbol).apply {
|
val containerConstructor = containerClass.primaryConstructor
|
||||||
putValueArgument(
|
if (containerConstructor == null) {
|
||||||
0,
|
logger.warnElement("Expected container class to have a primary constructor", containerClass)
|
||||||
IrVarargImpl(
|
return null
|
||||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET,
|
} else {
|
||||||
pluginContext.irBuiltIns.arrayClass.typeWith(annotationType),
|
return IrConstructorCallImpl.fromSymbolOwner(containerClass.defaultType, containerConstructor.symbol).apply {
|
||||||
annotationType,
|
putValueArgument(
|
||||||
entries
|
0,
|
||||||
|
IrVarargImpl(
|
||||||
|
UNDEFINED_OFFSET, UNDEFINED_OFFSET,
|
||||||
|
pluginContext.irBuiltIns.arrayClass.typeWith(annotationType),
|
||||||
|
annotationType,
|
||||||
|
entries
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -560,11 +566,15 @@ open class KotlinFileExtractor(
|
|||||||
.filterIsInstance<IrProperty>()
|
.filterIsInstance<IrProperty>()
|
||||||
.first { it.name == param.name }
|
.first { it.name == param.name }
|
||||||
val v = constructorCall.getValueArgument(i) ?: param.defaultValue?.expression
|
val v = constructorCall.getValueArgument(i) ?: param.defaultValue?.expression
|
||||||
val getter = prop.getter!!
|
val getter = prop.getter
|
||||||
val getterId = useFunction<DbMethod>(getter)
|
if (getter == null) {
|
||||||
val exprId = extractAnnotationValueExpression(v, id, i, "{${getterId}}", getter.returnType)
|
logger.warnElement("Expected annotation property to define a getter", prop)
|
||||||
if (exprId != null) {
|
} else {
|
||||||
tw.writeAnnotValue(id, getterId, exprId)
|
val getterId = useFunction<DbMethod>(getter)
|
||||||
|
val exprId = extractAnnotationValueExpression(v, id, i, "{${getterId}}", getter.returnType)
|
||||||
|
if (exprId != null) {
|
||||||
|
tw.writeAnnotValue(id, getterId, exprId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return id
|
return id
|
||||||
@@ -599,22 +609,26 @@ open class KotlinFileExtractor(
|
|||||||
// Use the context type (i.e., the type the annotation expects, not the actual type of the array)
|
// Use the context type (i.e., the type the annotation expects, not the actual type of the array)
|
||||||
// because the Java extractor fills in array types using the same technique. These should only
|
// because the Java extractor fills in array types using the same technique. These should only
|
||||||
// differ for generic annotations.
|
// differ for generic annotations.
|
||||||
val type = useType(kClassToJavaClass(contextType!!))
|
if (contextType == null) {
|
||||||
tw.writeExprs_arrayinit(arrayId, type.javaResult.id, parent, idx)
|
logger.warnElement("Expected an annotation array to have an enclosing context", v)
|
||||||
tw.writeExprsKotlinType(arrayId, type.kotlinResult.id)
|
} else {
|
||||||
tw.writeHasLocation(arrayId, tw.getLocation(v))
|
val type = useType(kClassToJavaClass(contextType))
|
||||||
|
tw.writeExprs_arrayinit(arrayId, type.javaResult.id, parent, idx)
|
||||||
|
tw.writeExprsKotlinType(arrayId, type.kotlinResult.id)
|
||||||
|
tw.writeHasLocation(arrayId, tw.getLocation(v))
|
||||||
|
|
||||||
v.elements.forEachIndexed { index, irVarargElement -> run {
|
v.elements.forEachIndexed { index, irVarargElement -> run {
|
||||||
val argExpr = when (irVarargElement) {
|
val argExpr = when (irVarargElement) {
|
||||||
is IrExpression -> irVarargElement
|
is IrExpression -> irVarargElement
|
||||||
is IrSpreadElement -> irVarargElement.expression
|
is IrSpreadElement -> irVarargElement.expression
|
||||||
else -> {
|
else -> {
|
||||||
logger.errorElement("Unrecognised IrVarargElement: " + irVarargElement.javaClass, irVarargElement)
|
logger.errorElement("Unrecognised IrVarargElement: " + irVarargElement.javaClass, irVarargElement)
|
||||||
null
|
null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
extractAnnotationValueExpression(argExpr, arrayId, index, "child;$index", null)
|
||||||
extractAnnotationValueExpression(argExpr, arrayId, index, "child;$index", null)
|
} }
|
||||||
} }
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// is IrErrorExpression
|
// is IrErrorExpression
|
||||||
@@ -900,9 +914,14 @@ open class KotlinFileExtractor(
|
|||||||
c.declarations
|
c.declarations
|
||||||
.filterIsInstance<IrProperty>()
|
.filterIsInstance<IrProperty>()
|
||||||
.map {
|
.map {
|
||||||
val getter = it.getter!!
|
val getter = it.getter
|
||||||
val label = extractFunction(getter, id, extractBody = false, extractMethodAndParameterTypeAccesses = true, extractAnnotations = true, null, listOf())
|
if (getter == null) {
|
||||||
tw.writeIsAnnotElem(label!!.cast<DbMethod>())
|
logger.warnElement("Expected an annotation property to have a getter", it)
|
||||||
|
} else {
|
||||||
|
extractFunction(getter, id, extractBody = false, extractMethodAndParameterTypeAccesses = true, extractAnnotations = true, null, listOf())?.also { functionLabel ->
|
||||||
|
tw.writeIsAnnotElem(functionLabel.cast())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
c.declarations.forEach { extractDeclaration(it, extractPrivateMembers = extractPrivateMembers, extractFunctionBodies = extractFunctionBodies, extractAnnotations = true) }
|
c.declarations.forEach { extractDeclaration(it, extractPrivateMembers = extractPrivateMembers, extractFunctionBodies = extractFunctionBodies, extractAnnotations = true) }
|
||||||
|
|||||||
Reference in New Issue
Block a user