Skip to content

Commit 125797c

Browse files
committed
Improve code quality
1 parent a3a93d8 commit 125797c

File tree

1 file changed

+22
-35
lines changed

1 file changed

+22
-35
lines changed

java/kotlin-extractor2/src/main/kotlin/entities/Expression.kt

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -221,42 +221,31 @@ OLD: KE1
221221
}
222222
*/
223223

224-
private fun isFunctionMatchingNames(
225-
symbol: KaFunctionSymbol,
224+
private fun KaFunctionSymbol.hasMatchingNames(
226225
name: CallableId,
227-
isExtension: Boolean = false,
226+
extensionReceiverClassName: ClassId? = null,
228227
nullability: KaTypeNullability = KaTypeNullability.UNKNOWN,
229-
extensionReceiverClassName: ClassId? = null
230228
): Boolean {
231229

232-
if (symbol.callableId != name)
230+
if (this.callableId != name)
233231
return false
234232

235-
if (!isExtension)
236-
return true
237-
238-
val receiverType = symbol.receiverParameter?.type
239-
if (receiverType == null)
240-
return false
241-
242-
if (receiverType.nullability != nullability)
243-
return false
244-
245-
if (receiverType.symbol?.classId != extensionReceiverClassName)
246-
return false
233+
val receiverType = this.receiverParameter?.type
234+
if (receiverType != null && extensionReceiverClassName != null) {
235+
return receiverType.nullability == nullability &&
236+
receiverType.symbol?.classId == extensionReceiverClassName
237+
}
247238

248-
return true
239+
return receiverType == null && extensionReceiverClassName == null
249240
}
250241

251-
private fun isFunctionMatchingName(
252-
symbol: KaFunctionSymbol,
242+
private fun KaFunctionSymbol.hasName(
253243
packageName: String,
254244
className: String?,
255245
functionName: String
256246
): Boolean {
257247

258-
return isFunctionMatchingNames(
259-
symbol,
248+
return this.hasMatchingNames(
260249
CallableId(
261250
FqName(packageName),
262251
if (className == null) null else FqName(className),
@@ -265,13 +254,13 @@ private fun isFunctionMatchingName(
265254
)
266255
}
267256

268-
private fun isNumericFunction(target: KaFunctionSymbol, functionName: String): Boolean {
269-
return isFunctionMatchingName(target, "kotlin", "Int", functionName) ||
270-
isFunctionMatchingName(target, "kotlin", "Byte", functionName) ||
271-
isFunctionMatchingName(target, "kotlin", "Short", functionName) ||
272-
isFunctionMatchingName(target, "kotlin", "Long", functionName) ||
273-
isFunctionMatchingName(target, "kotlin", "Float", functionName) ||
274-
isFunctionMatchingName(target, "kotlin", "Double", functionName)
257+
private fun KaFunctionSymbol.isNumericWithName(functionName: String): Boolean {
258+
return this.hasName("kotlin", "Int", functionName) ||
259+
this.hasName("kotlin", "Byte", functionName) ||
260+
this.hasName("kotlin", "Short", functionName) ||
261+
this.hasName("kotlin", "Long", functionName) ||
262+
this.hasName("kotlin", "Float", functionName) ||
263+
this.hasName("kotlin", "Double", functionName)
275264
}
276265

277266
/**
@@ -305,14 +294,12 @@ private fun KotlinFileExtractor.extractBinaryExpression(
305294
TODO()
306295
}
307296

308-
if (isNumericFunction(target, "plus") ||
309-
isFunctionMatchingName(target, "kotlin", "String", "plus") ||
310-
isFunctionMatchingNames(
311-
target,
297+
if (target.isNumericWithName("plus") ||
298+
target.hasName("kotlin", "String", "plus") ||
299+
target.hasMatchingNames(
312300
CallableId(FqName("kotlin"), null, Name.identifier("plus")),
313-
isExtension = true,
301+
ClassId(FqName("kotlin"), Name.identifier("String")),
314302
nullability = KaTypeNullability.NULLABLE,
315-
ClassId(FqName("kotlin"), Name.identifier("String"))
316303
)
317304
) {
318305
val id = tw.getFreshIdLabel<DbAddexpr>()

0 commit comments

Comments
 (0)