Skip to content
This repository was archived by the owner on May 12, 2024. It is now read-only.

Commit 16ab461

Browse files
authored
Merge pull request #52 from AlexProgrammerDE/main
Added more method call downgraders
2 parents 482795d + 93566f1 commit 16ab461

4 files changed

Lines changed: 91 additions & 0 deletions

File tree

src/main/java/net/raphimc/javadowngrader/transformer/j11/Java12ToJava11.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import net.raphimc.javadowngrader.transformer.DowngradingTransformer;
2121
import net.raphimc.javadowngrader.transformer.j11.methodcallreplacer.ClassArrayTypeMCR;
2222
import net.raphimc.javadowngrader.transformer.j11.methodcallreplacer.CompletableFutureExceptionallyAsyncMCR;
23+
import net.raphimc.javadowngrader.transformer.j11.methodcallreplacer.StringDescribeConstableMCR;
2324
import org.objectweb.asm.Opcodes;
2425

2526
public class Java12ToJava11 extends DowngradingTransformer {
@@ -30,6 +31,8 @@ public Java12ToJava11() {
3031
this.addMethodCallReplacer(Opcodes.INVOKEVIRTUAL, "java/util/concurrent/CompletableFuture", "exceptionallyAsync", "(Ljava/util/function/Function;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;", new CompletableFutureExceptionallyAsyncMCR());
3132

3233
this.addMethodCallReplacer(Opcodes.INVOKEVIRTUAL, "java/lang/Class", "arrayType", "()Ljava/lang/Class;", new ClassArrayTypeMCR());
34+
35+
this.addMethodCallReplacer(Opcodes.INVOKEVIRTUAL, "java/lang/String", "describeConstable", "()Ljava/util/Optional;", new StringDescribeConstableMCR());
3336
}
3437

3538
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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.j11.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.MethodInsnNode;
27+
import org.objectweb.asm.tree.MethodNode;
28+
29+
public class StringDescribeConstableMCR implements MethodCallReplacer {
30+
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+
// String
36+
replacement.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/util/Optional", "of", "(Ljava/lang/String;)Ljava/util/Optional;"));
37+
// Optional
38+
39+
return replacement;
40+
}
41+
42+
}

src/main/java/net/raphimc/javadowngrader/transformer/j9/Java10ToJava9.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public Java10ToJava9() {
3939
this.addMethodCallReplacer(Opcodes.INVOKEVIRTUAL, "java/util/Optional", "orElseThrow", "()Ljava/lang/Object;", new OptionalOrElseThrowMCR());
4040

4141
this.addMethodCallReplacer(Opcodes.INVOKESTATIC, "java/net/URLEncoder", "encode", "(Ljava/lang/String;Ljava/nio/charset/Charset;)Ljava/lang/String;", new URLEncoderEncodeMCR());
42+
43+
this.addMethodCallReplacer(Opcodes.INVOKEVIRTUAL, "java/io/ByteArrayOutputStream", "toString", "(Ljava/nio/charset/Charset;)Ljava/lang/String;", new ByteArrayOutputStreamToStringMCR());
4244
}
4345

4446
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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.j9.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.MethodInsnNode;
27+
import org.objectweb.asm.tree.MethodNode;
28+
29+
public class ByteArrayOutputStreamToStringMCR implements MethodCallReplacer {
30+
31+
@Override
32+
public InsnList getReplacement(ClassNode classNode, MethodNode methodNode, String originalName, String originalDesc, RuntimeDepCollector depCollector, DowngradeResult result) {
33+
final InsnList replacement = new InsnList();
34+
35+
// ByteArrayOutputStream Charset
36+
replacement.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/nio/charset/Charset", "name", "()Ljava/lang/String;"));
37+
// ByteArrayOutputStream String
38+
replacement.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/io/ByteArrayOutputStream", "toString", "(Ljava/lang/String;)Ljava/lang/String;"));
39+
// String
40+
41+
return replacement;
42+
}
43+
44+
}

0 commit comments

Comments
 (0)