|
| 1 | +/* |
| 2 | + * This file is part of JavaDowngrader - https://github.com/RaphiMC/JavaDowngrader |
| 3 | + * Copyright (C) 2023 RK_01/RaphiMC and contributors |
| 4 | + * |
| 5 | + * This program is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU General Public License as published by |
| 7 | + * the Free Software Foundation, either version 3 of the License, or |
| 8 | + * (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.j14.methodcallreplacer; |
| 19 | + |
| 20 | +import net.raphimc.javadowngrader.transformer.MethodCallReplacer; |
| 21 | +import org.objectweb.asm.Opcodes; |
| 22 | +import org.objectweb.asm.tree.*; |
| 23 | + |
| 24 | +public class CharSequenceIsEmptyMCR implements MethodCallReplacer { |
| 25 | + |
| 26 | + @Override |
| 27 | + public InsnList getReplacement(ClassNode classNode, MethodNode method, String originalName, String originalDesc) { |
| 28 | + final InsnList replacement = new InsnList(); |
| 29 | + |
| 30 | + LabelNode ifNeq = new LabelNode(); |
| 31 | + LabelNode end = new LabelNode(); |
| 32 | + |
| 33 | + // CharSequence |
| 34 | + replacement.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, "java/lang/CharSequence", "length", "()I")); |
| 35 | + // int |
| 36 | + replacement.add(new InsnNode(Opcodes.ICONST_0)); |
| 37 | + // int, int |
| 38 | + replacement.add(new JumpInsnNode(Opcodes.IF_ICMPNE, ifNeq)); |
| 39 | + |
| 40 | + // |
| 41 | + replacement.add(new InsnNode(Opcodes.ICONST_1)); |
| 42 | + // int |
| 43 | + replacement.add(new JumpInsnNode(Opcodes.GOTO, end)); |
| 44 | + |
| 45 | + // |
| 46 | + replacement.add(ifNeq); |
| 47 | + replacement.add(new InsnNode(Opcodes.ICONST_0)); |
| 48 | + // int |
| 49 | + replacement.add(end); |
| 50 | + |
| 51 | + return replacement; |
| 52 | + } |
| 53 | + |
| 54 | +} |
0 commit comments