Skip to content

Commit

Permalink
begin java 22 support
Browse files Browse the repository at this point in the history
  • Loading branch information
wagyourtail committed Jun 7, 2024
1 parent 7b70270 commit aaffd1d
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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();
}

}
Original file line number Diff line number Diff line change
@@ -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);
};
}

}
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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);

}

Expand Down

0 comments on commit aaffd1d

Please sign in to comment.