From aaffd1d1ee0d3a1188020cbf266087755970bb7e Mon Sep 17 00:00:00 2001 From: Wagyourtail Date: Fri, 7 Jun 2024 18:29:34 -0500 Subject: [PATCH] begin java 22 support --- .../jvmdg/j22/stub/java_base/J_I_Console.java | 28 +++++++++++++++++++ .../jvmdg/j22/stub/java_base/J_L_Class.java | 23 +++++++++++++++ .../jvmdg/j22/stub/java_base/J_N_F_Path.java | 27 ++++++++++++++++++ .../jvmdg/providers/Java22Downgrader.java | 5 ++++ 4 files changed, 83 insertions(+) create mode 100644 java-api/src/java22/java/xyz/wagyourtail/jvmdg/j22/stub/java_base/J_I_Console.java create mode 100644 java-api/src/java22/java/xyz/wagyourtail/jvmdg/j22/stub/java_base/J_L_Class.java create mode 100644 java-api/src/java22/java/xyz/wagyourtail/jvmdg/j22/stub/java_base/J_N_F_Path.java diff --git a/java-api/src/java22/java/xyz/wagyourtail/jvmdg/j22/stub/java_base/J_I_Console.java b/java-api/src/java22/java/xyz/wagyourtail/jvmdg/j22/stub/java_base/J_I_Console.java new file mode 100644 index 00000000..6d90541f --- /dev/null +++ b/java-api/src/java22/java/xyz/wagyourtail/jvmdg/j22/stub/java_base/J_I_Console.java @@ -0,0 +1,28 @@ +package xyz.wagyourtail.jvmdg.j22.stub.java_base; + +import xyz.wagyourtail.jvmdg.util.Utils; +import xyz.wagyourtail.jvmdg.version.Stub; + +import java.io.Console; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; + +public class J_I_Console { + private static final MethodHandles.Lookup IMPL_LOOKUP = Utils.getImplLookup(); + private static final MethodHandle ISTTY; + + static { + try { + ISTTY = IMPL_LOOKUP.findStatic(Console.class, "istty", MethodType.methodType(boolean.class)); + } catch (NoSuchMethodException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + @Stub + public static boolean isTerminal(Console console) throws Throwable { + return console.getClass().equals(Console.class) && (boolean) ISTTY.invokeExact(); + } + +} diff --git a/java-api/src/java22/java/xyz/wagyourtail/jvmdg/j22/stub/java_base/J_L_Class.java b/java-api/src/java22/java/xyz/wagyourtail/jvmdg/j22/stub/java_base/J_L_Class.java new file mode 100644 index 00000000..7e3e3561 --- /dev/null +++ b/java-api/src/java22/java/xyz/wagyourtail/jvmdg/j22/stub/java_base/J_L_Class.java @@ -0,0 +1,23 @@ +package xyz.wagyourtail.jvmdg.j22.stub.java_base; + +import xyz.wagyourtail.jvmdg.version.Ref; +import xyz.wagyourtail.jvmdg.version.Stub; + +public class J_L_Class { + + @Stub(ref = @Ref("java/lang/Class")) + public static Class forPrimitiveName(String name) { + return switch (name) { + case "boolean" -> boolean.class; + case "byte" -> byte.class; + case "char" -> char.class; + case "short" -> short.class; + case "int" -> int.class; + case "long" -> long.class; + case "float" -> float.class; + case "double" -> double.class; + default -> throw new IllegalArgumentException("Unknown primitive type: " + name); + }; + } + +} diff --git a/java-api/src/java22/java/xyz/wagyourtail/jvmdg/j22/stub/java_base/J_N_F_Path.java b/java-api/src/java22/java/xyz/wagyourtail/jvmdg/j22/stub/java_base/J_N_F_Path.java new file mode 100644 index 00000000..8b229a9c --- /dev/null +++ b/java-api/src/java22/java/xyz/wagyourtail/jvmdg/j22/stub/java_base/J_N_F_Path.java @@ -0,0 +1,27 @@ +package xyz.wagyourtail.jvmdg.j22.stub.java_base; + +import xyz.wagyourtail.jvmdg.version.Stub; + +import java.nio.file.Path; + +public class J_N_F_Path { + + @Stub + public static Path resolve(Path self, String first, String... more) { + Path result = self.resolve(first); + for (String path : more) { + result = result.resolve(path); + } + return result; + } + + @Stub + public static Path resolve(Path self, Path first, Path... more) { + Path result = self.resolve(first); + for (Path path : more) { + result = result.resolve(path); + } + return result; + } + +} diff --git a/java-api/src/main/java/xyz/wagyourtail/jvmdg/providers/Java22Downgrader.java b/java-api/src/main/java/xyz/wagyourtail/jvmdg/providers/Java22Downgrader.java index c20c242a..527db21c 100644 --- a/java-api/src/main/java/xyz/wagyourtail/jvmdg/providers/Java22Downgrader.java +++ b/java-api/src/main/java/xyz/wagyourtail/jvmdg/providers/Java22Downgrader.java @@ -1,6 +1,7 @@ package xyz.wagyourtail.jvmdg.providers; import org.objectweb.asm.Opcodes; +import xyz.wagyourtail.jvmdg.j22.stub.java_base.*; import xyz.wagyourtail.jvmdg.version.VersionProvider; public class Java22Downgrader extends VersionProvider { @@ -11,6 +12,10 @@ public Java22Downgrader() { @Override public void init() { + // -- java.base -- + stub(J_I_Console.class); + stub(J_L_Class.class); + stub(J_N_F_Path.class); }