|
| 1 | +/* |
| 2 | + * This file is part of JavaDowngrader - https://github.com/RaphiMC/JavaDowngrader |
| 3 | + * Copyright (C) 2023-2024 RK_01/RaphiMC and contributors |
| 4 | + * |
| 5 | + * This program is free software; you can redistribute it and/or |
| 6 | + * modify it under the terms of the GNU Lesser General Public |
| 7 | + * License as published by the Free Software Foundation; either |
| 8 | + * version 3 of the License, or (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License |
| 16 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + */ |
| 18 | +package net.raphimc.javadowngrader.transformer.j8.methodcallreplacer; |
| 19 | + |
| 20 | +import net.raphimc.javadowngrader.RuntimeDepCollector; |
| 21 | +import net.raphimc.javadowngrader.transformer.DowngradeResult; |
| 22 | +import net.raphimc.javadowngrader.transformer.MethodCallReplacer; |
| 23 | +import org.objectweb.asm.Opcodes; |
| 24 | +import org.objectweb.asm.tree.ClassNode; |
| 25 | +import org.objectweb.asm.tree.InsnList; |
| 26 | +import org.objectweb.asm.tree.InsnNode; |
| 27 | +import org.objectweb.asm.tree.MethodInsnNode; |
| 28 | +import org.objectweb.asm.tree.MethodNode; |
| 29 | + |
| 30 | +public class IntegerParseIntMCR implements MethodCallReplacer { |
| 31 | + @Override |
| 32 | + public InsnList getReplacement(ClassNode classNode, MethodNode method, String originalName, String originalDesc, RuntimeDepCollector depCollector, DowngradeResult result) { |
| 33 | + final InsnList replacement = new InsnList(); |
| 34 | + |
| 35 | + // CharSequence start end radix |
| 36 | + replacement.add(new InsnNode(Opcodes.DUP2_X2)); |
| 37 | + // end radix CharSequence start end radix |
| 38 | + replacement.add(new InsnNode(Opcodes.POP)); |
| 39 | + // end radix CharSequence start end |
| 40 | + replacement.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, "java/lang/CharSequence", "subSequence", "(II)Ljava/lang/CharSequence;")); |
| 41 | + // end radix CharSequence |
| 42 | + replacement.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, "java/lang/CharSequence", "toString", "()Ljava/lang/String;")); |
| 43 | + // end radix String |
| 44 | + replacement.add(new InsnNode(Opcodes.SWAP)); |
| 45 | + // end String radix |
| 46 | + replacement.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Integer", originalName, "(Ljava/lang/String;I)I")); |
| 47 | + // end result |
| 48 | + replacement.add(new InsnNode(Opcodes.SWAP)); |
| 49 | + // result end |
| 50 | + replacement.add(new InsnNode(Opcodes.POP)); |
| 51 | + // result |
| 52 | + |
| 53 | + return replacement; |
| 54 | + } |
| 55 | +} |
0 commit comments