Fix various style warnings highlighted by IntelliJ

This commit is contained in:
Chris Smowton
2021-11-17 15:42:14 +00:00
committed by Ian Lynagh
parent 8f5bbc7bd8
commit 970e3d64c0

View File

@@ -90,7 +90,7 @@ class StringLabel<T>(val name: String): Label<T> {
override fun toString(): String = "#$name"
}
class StarLabel<T>(): Label<T> {
class StarLabel<T>: Label<T> {
override fun toString(): String = "*"
}
@@ -197,7 +197,7 @@ class ExternalClassExtractor(val logger: FileLogger, val sourceFilePath: String,
val output = OdasaOutput(false, logger)
output.setCurrentSourceFile(File(sourceFilePath))
do {
val nextBatch = ArrayList<IrClass>(externalClassWorkList)
val nextBatch = ArrayList(externalClassWorkList)
externalClassWorkList.clear()
nextBatch.forEach { irClass ->
output.getTrapLockerForClassFile(irClass).useAC { locker ->
@@ -214,7 +214,7 @@ class ExternalClassExtractor(val logger: FileLogger, val sourceFilePath: String,
}
}
}
} while (!externalClassWorkList.isEmpty());
} while (externalClassWorkList.isNotEmpty())
output.writeTrapSet()
}
@@ -326,15 +326,14 @@ open class KotlinUsesExtractor(
data class TypeResult<LabelType>(val id: Label<LabelType>, val signature: String)
data class TypeResults(val javaResult: TypeResult<out DbType>, val kotlinResult: TypeResult<out DbKt_type>)
fun useType(t: IrType, canReturnPrimitiveTypes: Boolean = true): TypeResults {
fun useType(t: IrType, canReturnPrimitiveTypes: Boolean = true) =
when(t) {
is IrSimpleType -> return useSimpleType(t, canReturnPrimitiveTypes)
is IrSimpleType -> useSimpleType(t, canReturnPrimitiveTypes)
else -> {
logger.warn(Severity.ErrorSevere, "Unrecognised IrType: " + t.javaClass)
return TypeResults(TypeResult(fakeLabel(), "unknown"), TypeResult(fakeLabel(), "unknown"))
TypeResults(TypeResult(fakeLabel(), "unknown"), TypeResult(fakeLabel(), "unknown"))
}
}
}
fun getJavaEquivalentClass(c: IrClass) =
c.fqNameWhenAvailable?.toUnsafe()
@@ -399,8 +398,7 @@ open class KotlinUsesExtractor(
}
fun extractExternalEnclosingClassLater(d: IrDeclaration) {
val parent = d.parent
when (parent) {
when (val parent = d.parent) {
is IrClass -> extractExternalClassLater(parent)
is IrFunction -> extractExternalEnclosingClassLater(parent)
is IrFile -> logger.warn(Severity.ErrorSevere, "extractExternalEnclosingClassLater but no enclosing class.")
@@ -413,11 +411,8 @@ open class KotlinUsesExtractor(
externalClassExtractor.extractLater(c)
}
fun addClassLabel(c: IrClass, typeArgs: List<IrTypeArgument>): Label<out DbClassorinterface> {
var label = getClassLabel(c, typeArgs)
val id: Label<DbClassorinterface> = tw.getLabelFor(label)
return id
}
fun addClassLabel(c: IrClass, typeArgs: List<IrTypeArgument>): Label<out DbClassorinterface> =
tw.getLabelFor(getClassLabel(c, typeArgs))
fun shortName(type: IrType, canReturnPrimitiveTypes: Boolean = true): String =
when(type) {
@@ -718,28 +713,31 @@ class X {
}
}
fun useDeclarationParent(dp: IrDeclarationParent): Label<out DbElement> {
fun useDeclarationParent(dp: IrDeclarationParent): Label<out DbElement> =
when(dp) {
is IrFile -> return usePackage(dp.fqName.asString())
is IrClass -> return useClassSource(dp)
is IrFunction -> return useFunction(dp)
is IrFile -> usePackage(dp.fqName.asString())
is IrClass -> useClassSource(dp)
is IrFunction -> useFunction(dp)
else -> {
logger.warn(Severity.ErrorSevere, "Unrecognised IrDeclarationParent: " + dp.javaClass)
return fakeLabel()
fakeLabel()
}
}
}
fun getFunctionLabel(f: IrFunction) : String {
return getFunctionLabel(f.parent, f.name.asString(), f.valueParameters, f.returnType)
}
fun getFunctionLabel(parent: IrDeclarationParent, name: String, parameters: List<IrValueParameter>, returnType: IrType) : String {
val paramTypeIds = parameters.joinToString() { "{${useType(erase(it.type)).javaResult.id.toString()}}" }
fun getFunctionLabel(
parent: IrDeclarationParent,
name: String,
parameters: List<IrValueParameter>,
returnType: IrType
): String {
val paramTypeIds = parameters.joinToString { "{${useType(erase(it.type)).javaResult.id}}" }
val returnTypeId = useType(erase(returnType)).javaResult.id
val parentId = useDeclarationParent(parent)
val label = "@\"callable;{$parentId}.$name($paramTypeIds){$returnTypeId}\""
return label
return "@\"callable;{$parentId}.$name($paramTypeIds){$returnTypeId}\""
}
fun <T: DbCallable> useFunction(f: IrFunction): Label<out T> {
@@ -797,12 +795,12 @@ class X {
val cls = c.name.asString()
var label: String
val parent = c.parent
if (parent is IrClass) {
label = if (parent is IrClass) {
// todo: fix this. Ugly string concat to handle nested class IDs.
// todo: Can the containing class have type arguments?
label = "${getUnquotedClassLabel(parent, listOf())}\$$cls"
"${getUnquotedClassLabel(parent, listOf())}\$$cls"
} else {
label = if (pkg.isEmpty()) cls else "$pkg.$cls"
if (pkg.isEmpty()) cls else "$pkg.$cls"
}
for (arg in typeArgs) {
@@ -857,13 +855,14 @@ class X {
for(t in c.superTypes) {
when(t) {
is IrSimpleType -> {
when {
t.classifier.owner is IrClass -> {
when (t.classifier.owner) {
is IrClass -> {
val classifier: IrClassifierSymbol = t.classifier
val tcls: IrClass = classifier.owner as IrClass
val l = useClassInstance(tcls, t.arguments).classLabel
tw.writeExtendsReftype(id, l)
} else -> {
}
else -> {
logger.warn(Severity.ErrorSevere, "Unexpected simple type supertype: " + t.javaClass + ": " + t.render())
}
}
@@ -874,27 +873,22 @@ class X {
}
}
fun useValueDeclaration(d: IrValueDeclaration): Label<out DbVariable> {
fun useValueDeclaration(d: IrValueDeclaration): Label<out DbVariable> =
when(d) {
is IrValueParameter -> {
return useValueParameter(d)
}
is IrVariable -> {
return useVariable(d)
}
is IrValueParameter -> useValueParameter(d)
is IrVariable -> useVariable(d)
else -> {
logger.warn(Severity.ErrorSevere, "Unrecognised IrValueDeclaration: " + d.javaClass)
return fakeLabel()
fakeLabel()
}
}
}
fun erase (t: IrType): IrType {
if (t is IrSimpleType) {
val classifier = t.classifier
val owner = classifier.owner
if(owner is IrTypeParameter) {
return erase(owner.superTypes.get(0))
return erase(owner.superTypes[0])
}
// todo: fix this:
@@ -911,47 +905,35 @@ class X {
return t
}
fun getValueParameterLabel(vp: IrValueParameter) : String {
fun getValueParameterLabel(vp: IrValueParameter): String {
@Suppress("UNCHECKED_CAST")
val parentId: Label<out DbMethod> = useDeclarationParent(vp.parent) as Label<out DbMethod>
var idx = vp.index
val idx = vp.index
if (idx < 0) {
// We're not extracting this and this@TYPE parameters of functions:
logger.warn(Severity.ErrorSevere, "Unexpected negative index for parameter")
}
val label = "@\"params;{$parentId};$idx\""
return label
return "@\"params;{$parentId};$idx\""
}
fun useValueParameter(vp: IrValueParameter): Label<out DbParam> {
val label = getValueParameterLabel(vp)
val id = tw.getLabelFor<DbParam>(label)
return id
}
fun useValueParameter(vp: IrValueParameter): Label<out DbParam> =
tw.getLabelFor(getValueParameterLabel(vp))
fun getFieldLabel(p: IrField) : String {
fun getFieldLabel(p: IrField): String {
val parentId = useDeclarationParent(p.parent)
val label = "@\"field;{$parentId};${p.name.asString()}\""
return label
return "@\"field;{$parentId};${p.name.asString()}\""
}
fun useField(p: IrField): Label<out DbField> {
var label = getFieldLabel(p)
val id: Label<DbField> = tw.getLabelFor(label)
return id
}
fun useField(p: IrField): Label<out DbField> =
tw.getLabelFor(getFieldLabel(p))
fun getPropertyLabel(p: IrProperty) : String {
fun getPropertyLabel(p: IrProperty): String {
val parentId = useDeclarationParent(p.parent)
val label = "@\"property;{$parentId};${p.name.asString()}\""
return label
return "@\"property;{$parentId};${p.name.asString()}\""
}
fun useProperty(p: IrProperty): Label<out DbKt_property> {
var label = getPropertyLabel(p)
val id: Label<DbKt_property> = tw.getLabelFor(label)
return id
}
fun useProperty(p: IrProperty): Label<out DbKt_property> =
tw.getLabelFor(getPropertyLabel(p))
private fun getEnumEntryLabel(ee: IrEnumEntry) : String {
val parentId = useDeclarationParent(ee.parent)
@@ -959,11 +941,8 @@ class X {
return label
}
fun useEnumEntry(ee: IrEnumEntry): Label<out DbField> {
var label = getEnumEntryLabel(ee)
val id: Label<DbField> = tw.getLabelFor(label)
return id
}
fun useEnumEntry(ee: IrEnumEntry): Label<out DbField> =
tw.getLabelFor(getEnumEntryLabel(ee))
private fun getTypeAliasLabel(ta: IrTypeAlias) : String {
val parentId = useDeclarationParent(ta.parent)
@@ -971,11 +950,8 @@ class X {
return label
}
fun useTypeAlias(ta: IrTypeAlias): Label<out DbKt_type_alias> {
var label = getTypeAliasLabel(ta)
val id: Label<DbKt_type_alias> = tw.getLabelFor(label)
return id
}
fun useTypeAlias(ta: IrTypeAlias): Label<out DbKt_type_alias> =
tw.getLabelFor(getTypeAliasLabel(ta))
fun useVariable(v: IrVariable): Label<out DbLocalvar> {
return tw.getVariableLabelFor<DbLocalvar>(v)
@@ -1122,7 +1098,7 @@ open class KotlinFileExtractor(
tw.writeEnclInReftype(id, parentId)
if(c.isCompanion) {
// If we are a companion then our parent has a
// public static final ParentClass$CompanionObjectClass CompanionObJectName;
// public static final ParentClass$CompanionObjectClass CompanionObjectName;
// that we need to fabricate here
val instance = useCompanionObjectClassInstance(c)
if(instance != null) {
@@ -1210,7 +1186,7 @@ open class KotlinFileExtractor(
}
// add method:
var obinitLabel = getFunctionLabel(c, "<obinit>", listOf(), pluginContext.irBuiltIns.unitType)
val obinitLabel = getFunctionLabel(c, "<obinit>", listOf(), pluginContext.irBuiltIns.unitType)
val obinitId = tw.getLabelFor<DbMethod>(obinitLabel)
val signature = "TODO"
val returnType = useType(pluginContext.irBuiltIns.unitType)
@@ -1359,7 +1335,7 @@ open class KotlinFileExtractor(
val parent = ee.parent
if(parent !is IrClass) {
logger.warnElement(Severity.ErrorSevere, "Enum entry with unexpected parent: " + parent.javaClass, ee)
} else if (!parent.typeParameters.isEmpty()) {
} else if (parent.typeParameters.isNotEmpty()) {
logger.warnElement(Severity.ErrorSevere, "Enum entry parent class has type parameters: " + parent.name, ee)
} else {
val type = useSimpleTypeClass(parent, emptyList(), false)
@@ -1438,8 +1414,8 @@ open class KotlinFileExtractor(
}
fun extractCall(c: IrCall, callable: Label<out DbCallable>, parent: Label<out DbExprparent>, idx: Int) {
val exprId: Label<out DbExpr> = when {
c.origin == PLUS -> {
val exprId: Label<out DbExpr> = when (c.origin) {
PLUS -> {
val id = tw.getFreshIdLabel<DbAddexpr>()
val type = useType(c.type)
val locId = tw.getLocation(c)
@@ -1447,7 +1423,8 @@ open class KotlinFileExtractor(
tw.writeHasLocation(id, locId)
tw.writeCallableEnclosingExpr(id, callable)
id
} c.origin == MINUS -> {
}
MINUS -> {
val id = tw.getFreshIdLabel<DbSubexpr>()
val type = useType(c.type)
val locId = tw.getLocation(c)
@@ -1455,7 +1432,8 @@ open class KotlinFileExtractor(
tw.writeHasLocation(id, locId)
tw.writeCallableEnclosingExpr(id, callable)
id
} c.origin == DIV -> {
}
DIV -> {
val id = tw.getFreshIdLabel<DbDivexpr>()
val type = useType(c.type)
val locId = tw.getLocation(c)
@@ -1463,7 +1441,8 @@ open class KotlinFileExtractor(
tw.writeHasLocation(id, locId)
tw.writeCallableEnclosingExpr(id, callable)
id
} c.origin == PERC -> {
}
PERC -> {
val id = tw.getFreshIdLabel<DbRemexpr>()
val type = useType(c.type)
val locId = tw.getLocation(c)
@@ -1471,7 +1450,8 @@ open class KotlinFileExtractor(
tw.writeHasLocation(id, locId)
tw.writeCallableEnclosingExpr(id, callable)
id
} c.origin == EQEQ -> {
}
EQEQ -> {
val id = tw.getFreshIdLabel<DbEqexpr>()
val type = useType(c.type)
val locId = tw.getLocation(c)
@@ -1479,7 +1459,8 @@ open class KotlinFileExtractor(
tw.writeHasLocation(id, locId)
tw.writeCallableEnclosingExpr(id, callable)
id
} c.origin == EXCLEQ -> {
}
EXCLEQ -> {
val id = tw.getFreshIdLabel<DbNeexpr>()
val type = useType(c.type)
val locId = tw.getLocation(c)
@@ -1487,7 +1468,8 @@ open class KotlinFileExtractor(
tw.writeHasLocation(id, locId)
tw.writeCallableEnclosingExpr(id, callable)
id
} c.origin == LT -> {
}
LT -> {
val id = tw.getFreshIdLabel<DbLtexpr>()
val type = useType(c.type)
val locId = tw.getLocation(c)
@@ -1495,7 +1477,8 @@ open class KotlinFileExtractor(
tw.writeHasLocation(id, locId)
tw.writeCallableEnclosingExpr(id, callable)
id
} c.origin == LTEQ -> {
}
LTEQ -> {
val id = tw.getFreshIdLabel<DbLeexpr>()
val type = useType(c.type)
val locId = tw.getLocation(c)
@@ -1503,7 +1486,8 @@ open class KotlinFileExtractor(
tw.writeHasLocation(id, locId)
tw.writeCallableEnclosingExpr(id, callable)
id
} c.origin == GT -> {
}
GT -> {
val id = tw.getFreshIdLabel<DbGtexpr>()
val type = useType(c.type)
val locId = tw.getLocation(c)
@@ -1511,7 +1495,8 @@ open class KotlinFileExtractor(
tw.writeHasLocation(id, locId)
tw.writeCallableEnclosingExpr(id, callable)
id
} c.origin == GTEQ -> {
}
GTEQ -> {
val id = tw.getFreshIdLabel<DbGeexpr>()
val type = useType(c.type)
val locId = tw.getLocation(c)
@@ -1519,7 +1504,8 @@ open class KotlinFileExtractor(
tw.writeHasLocation(id, locId)
tw.writeCallableEnclosingExpr(id, callable)
id
} else -> {
}
else -> {
val id = tw.getFreshIdLabel<DbMethodaccess>()
val type = useType(c.type)
val locId = tw.getLocation(c)
@@ -1783,7 +1769,7 @@ open class KotlinFileExtractor(
val id = tw.getFreshIdLabel<DbMethodaccess>()
val type = useType(e.type)
val locId = tw.getLocation(e)
var methodLabel = getFunctionLabel(irCallable.parent, "<obinit>", listOf(), e.type)
val methodLabel = getFunctionLabel(irCallable.parent, "<obinit>", listOf(), e.type)
val methodId = tw.getLabelFor<DbMethod>(methodLabel)
tw.writeExprs_methodaccess(id, type.javaResult.id, type.kotlinResult.id, exprParent.parent, exprParent.idx)
tw.writeHasLocation(id, locId)
@@ -1816,8 +1802,7 @@ open class KotlinFileExtractor(
}
is IrConst<*> -> {
val exprParent = parent.expr(e, callable)
val v = e.value
when(v) {
when(val v = e.value) {
is Int, is Short, is Byte -> {
val id = tw.getFreshIdLabel<DbIntegerliteral>()
val type = useType(e.type)
@@ -1899,8 +1884,7 @@ open class KotlinFileExtractor(
tw.writeHasLocation(id, locId)
tw.writeCallableEnclosingExpr(id, callable)
val ownerParent = owner.parent
when(ownerParent) {
when(val ownerParent = owner.parent) {
is IrFunction -> {
if (ownerParent.dispatchReceiverParameter == owner &&
ownerParent.extensionReceiverParameter != null) {
@@ -1971,20 +1955,24 @@ open class KotlinFileExtractor(
tw.writeHasLocation(id, locId)
tw.writeCallableEnclosingExpr(lhsId, callable)
if (e is IrSetValue) {
val lhsType = useType(e.symbol.owner.type)
tw.writeExprs_varaccess(lhsId, lhsType.javaResult.id, lhsType.kotlinResult.id, id, 0)
val vId = useValueDeclaration(e.symbol.owner)
tw.writeVariableBinding(lhsId, vId)
extractExpressionExpr(e.value, callable, id, 1)
} else if (e is IrSetField) {
val lhsType = useType(e.symbol.owner.type)
tw.writeExprs_varaccess(lhsId, lhsType.javaResult.id, lhsType.kotlinResult.id, id, 0)
val vId = useField(e.symbol.owner)
tw.writeVariableBinding(lhsId, vId)
extractExpressionExpr(e.value, callable, id, 1)
} else {
logger.warnElement(Severity.ErrorSevere, "Unhandled IrSet* element.", e)
when (e) {
is IrSetValue -> {
val lhsType = useType(e.symbol.owner.type)
tw.writeExprs_varaccess(lhsId, lhsType.javaResult.id, lhsType.kotlinResult.id, id, 0)
val vId = useValueDeclaration(e.symbol.owner)
tw.writeVariableBinding(lhsId, vId)
extractExpressionExpr(e.value, callable, id, 1)
}
is IrSetField -> {
val lhsType = useType(e.symbol.owner.type)
tw.writeExprs_varaccess(lhsId, lhsType.javaResult.id, lhsType.kotlinResult.id, id, 0)
val vId = useField(e.symbol.owner)
tw.writeVariableBinding(lhsId, vId)
extractExpressionExpr(e.value, callable, id, 1)
}
else -> {
logger.warnElement(Severity.ErrorSevere, "Unhandled IrSet* element.", e)
}
}
}
is IrWhen -> {