Code clean
This commit is contained in:
@@ -205,56 +205,28 @@ private fun getInlineName(
|
||||
internal fun isInvokeOnLambda(owner: String, name: String): Boolean {
|
||||
return OperatorNameConventions.INVOKE.asString() == name &&
|
||||
owner.startsWith(NUMBERED_FUNCTION_PREFIX) &&
|
||||
isInteger(owner.substring(NUMBERED_FUNCTION_PREFIX.length))
|
||||
owner.substring(NUMBERED_FUNCTION_PREFIX.length).isInteger()
|
||||
}
|
||||
|
||||
internal fun isAnonymousConstructorCall(internalName: String, methodName: String): Boolean {
|
||||
return "<init>" == methodName && isAnonymousClass(internalName)
|
||||
}
|
||||
internal fun isAnonymousConstructorCall(internalName: String, methodName: String): Boolean =
|
||||
isConstructor(methodName) && isAnonymousClass(internalName)
|
||||
|
||||
internal fun isWhenMappingAccess(internalName: String, fieldName: String): Boolean {
|
||||
return fieldName.startsWith(WhenByEnumsMapping.MAPPING_ARRAY_FIELD_PREFIX) && internalName.endsWith(WhenByEnumsMapping.MAPPINGS_CLASS_NAME_POSTFIX)
|
||||
}
|
||||
private fun isConstructor(methodName: String) = "<init>" == methodName
|
||||
|
||||
internal fun isAnonymousSingletonLoad(internalName: String, fieldName: String): Boolean {
|
||||
return JvmAbi.INSTANCE_FIELD == fieldName && isAnonymousClass(internalName)
|
||||
}
|
||||
internal fun isWhenMappingAccess(internalName: String, fieldName: String): Boolean =
|
||||
fieldName.startsWith(WhenByEnumsMapping.MAPPING_ARRAY_FIELD_PREFIX) && internalName.endsWith(WhenByEnumsMapping.MAPPINGS_CLASS_NAME_POSTFIX)
|
||||
|
||||
internal fun isAnonymousSingletonLoad(internalName: String, fieldName: String): Boolean =
|
||||
JvmAbi.INSTANCE_FIELD == fieldName && isAnonymousClass(internalName)
|
||||
|
||||
internal fun isAnonymousClass(internalName: String): Boolean {
|
||||
val shortName = getLastNamePart(internalName)
|
||||
val index = shortName.lastIndexOf("$")
|
||||
|
||||
if (index < 0) {
|
||||
return false
|
||||
}
|
||||
|
||||
val suffix = shortName.substring(index + 1)
|
||||
return isInteger(suffix)
|
||||
return internalName.substringAfterLast('/').substringAfterLast("$", "").isInteger()
|
||||
}
|
||||
|
||||
private fun getLastNamePart(internalName: String): String {
|
||||
val index = internalName.lastIndexOf("/")
|
||||
return if (index < 0) internalName else internalName.substring(index + 1)
|
||||
}
|
||||
fun wrapWithMaxLocalCalc(methodNode: MethodNode) =
|
||||
MaxStackFrameSizeAndLocalsCalculator(API, methodNode.access, methodNode.desc, methodNode)
|
||||
|
||||
fun wrapWithMaxLocalCalc(methodNode: MethodNode): MethodVisitor {
|
||||
return MaxStackFrameSizeAndLocalsCalculator(API, methodNode.access, methodNode.desc, methodNode)
|
||||
}
|
||||
|
||||
private fun isInteger(string: String): Boolean {
|
||||
string.toIntOrNull() != null
|
||||
if (string.isEmpty()) {
|
||||
return false
|
||||
}
|
||||
|
||||
for (i in 0..string.length - 1) {
|
||||
if (!Character.isDigit(string[i])) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
private fun String.isInteger(radix: Int = 10) = toIntOrNull(radix) != null
|
||||
|
||||
internal fun isCapturedFieldName(fieldName: String): Boolean {
|
||||
// TODO: improve this heuristic
|
||||
@@ -263,14 +235,10 @@ internal fun isCapturedFieldName(fieldName: String): Boolean {
|
||||
RECEIVER_0 == fieldName
|
||||
}
|
||||
|
||||
internal fun isReturnOpcode(opcode: Int): Boolean {
|
||||
return opcode >= Opcodes.IRETURN && opcode <= Opcodes.RETURN
|
||||
}
|
||||
internal fun isReturnOpcode(opcode: Int) = opcode >= Opcodes.IRETURN && opcode <= Opcodes.RETURN
|
||||
|
||||
//marked return could be either non-local or local in case of labeled lambda self-returns
|
||||
internal fun isMarkedReturn(returnIns: AbstractInsnNode): Boolean {
|
||||
return getMarkedReturnLabelOrNull(returnIns) != null
|
||||
}
|
||||
internal fun isMarkedReturn(returnIns: AbstractInsnNode) = getMarkedReturnLabelOrNull(returnIns) != null
|
||||
|
||||
internal fun getMarkedReturnLabelOrNull(returnInsn: AbstractInsnNode): String? {
|
||||
if (!isReturnOpcode(returnInsn.opcode)) {
|
||||
@@ -308,9 +276,7 @@ internal fun insertNodeBefore(from: MethodNode, to: MethodNode, beforeNode: Abst
|
||||
}
|
||||
}
|
||||
|
||||
internal fun createEmptyMethodNode(): MethodNode {
|
||||
return MethodNode(API, 0, "fake", "()V", null, null)
|
||||
}
|
||||
internal fun createEmptyMethodNode() = MethodNode(API, 0, "fake", "()V", null, null)
|
||||
|
||||
internal fun firstLabelInChain(node: LabelNode): LabelNode {
|
||||
var curNode = node
|
||||
@@ -345,9 +311,7 @@ internal val AbstractInsnNode?.insnText: String
|
||||
}
|
||||
|
||||
internal val AbstractInsnNode?.insnOpcodeText: String
|
||||
get() {
|
||||
return if (this == null) "null" else Printer.OPCODES[opcode]
|
||||
}
|
||||
get() = if (this == null) "null" else Printer.OPCODES[opcode]
|
||||
|
||||
internal fun buildClassReaderByInternalName(state: GenerationState, internalName: String): ClassReader {
|
||||
//try to find just compiled classes then in dependencies
|
||||
@@ -367,26 +331,18 @@ internal fun generateFinallyMarker(v: InstructionAdapter, depth: Int, start: Boo
|
||||
v.invokestatic(INLINE_MARKER_CLASS_NAME, if (start) INLINE_MARKER_FINALLY_START else INLINE_MARKER_FINALLY_END, "(I)V", false)
|
||||
}
|
||||
|
||||
internal fun isFinallyEnd(node: AbstractInsnNode): Boolean {
|
||||
return isFinallyMarker(node, INLINE_MARKER_FINALLY_END)
|
||||
}
|
||||
internal fun isFinallyEnd(node: AbstractInsnNode) = isFinallyMarker(node, INLINE_MARKER_FINALLY_END)
|
||||
|
||||
internal fun isFinallyStart(node: AbstractInsnNode): Boolean {
|
||||
return isFinallyMarker(node, INLINE_MARKER_FINALLY_START)
|
||||
}
|
||||
internal fun isFinallyStart(node: AbstractInsnNode) = isFinallyMarker(node, INLINE_MARKER_FINALLY_START)
|
||||
|
||||
internal fun isFinallyMarker(node: AbstractInsnNode?): Boolean {
|
||||
return node != null && (isFinallyStart(node) || isFinallyEnd(node))
|
||||
}
|
||||
internal fun isFinallyMarker(node: AbstractInsnNode?): Boolean = node != null && (isFinallyStart(node) || isFinallyEnd(node))
|
||||
|
||||
private fun isFinallyMarker(node: AbstractInsnNode, name: String): Boolean {
|
||||
if (node !is MethodInsnNode) return false
|
||||
return INLINE_MARKER_CLASS_NAME == node.owner && name == node.name
|
||||
}
|
||||
|
||||
internal fun isFinallyMarkerRequired(context: MethodContext): Boolean {
|
||||
return context.isInlineMethodContext || context is InlineLambdaContext
|
||||
}
|
||||
internal fun isFinallyMarkerRequired(context: MethodContext) = context.isInlineMethodContext || context is InlineLambdaContext
|
||||
|
||||
internal fun getConstant(ins: AbstractInsnNode): Int {
|
||||
val opcode = ins.opcode
|
||||
@@ -491,9 +447,7 @@ fun isFakeLocalVariableForInline(name: String): Boolean {
|
||||
return name.startsWith(JvmAbi.LOCAL_VARIABLE_NAME_PREFIX_INLINE_FUNCTION) || name.startsWith(JvmAbi.LOCAL_VARIABLE_NAME_PREFIX_INLINE_ARGUMENT)
|
||||
}
|
||||
|
||||
internal fun isThis0(name: String): Boolean {
|
||||
return THIS_0 == name
|
||||
}
|
||||
internal fun isThis0(name: String): Boolean = THIS_0 == name
|
||||
|
||||
internal fun isSpecialEnumMethod(functionDescriptor: FunctionDescriptor): Boolean {
|
||||
val containingDeclaration = functionDescriptor.containingDeclaration as? PackageFragmentDescriptor ?: return false
|
||||
|
||||
Reference in New Issue
Block a user