Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
wagyourtail committed Aug 6, 2024
1 parent 9980354 commit e668a0d
Show file tree
Hide file tree
Showing 22 changed files with 92 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@
import xyz.wagyourtail.jvmdg.util.Pair;
import xyz.wagyourtail.jvmdg.util.Utils;
import xyz.wagyourtail.jvmdg.version.Adapter;
import xyz.wagyourtail.jvmdg.version.CoverageIgnore;
import xyz.wagyourtail.jvmdg.version.Modify;
import xyz.wagyourtail.jvmdg.version.Stub;
import xyz.wagyourtail.jvmdg.version.map.ClassMapping;
import xyz.wagyourtail.jvmdg.version.map.FullyQualifiedMemberNameAndDesc;
import xyz.wagyourtail.jvmdg.version.map.MemberNameAndDesc;

import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Executable;
import java.lang.reflect.Member;
import java.net.URISyntaxException;
import java.net.URL;
Expand Down Expand Up @@ -94,11 +99,17 @@ public static void main(String[] args) throws IOException, URISyntaxException {

Map<Type, Type> stubClassTypes = versionProvider.classStubs.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().getFirst()));
Set<FullyQualifiedMemberNameAndDesc> stubClassMethods = versionProvider.classStubs.entrySet().stream().flatMap (e ->
Stream.<Member>concat(
Stream.concat(
Arrays.stream(e.getValue().getSecond().getFirst().getDeclaredMethods()),
Arrays.stream(e.getValue().getSecond().getFirst().getConstructors())
).filter(m -> (m.getModifiers() & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) != 0 && (m.getModifiers() & Opcodes.ACC_SYNTHETIC) == 0)
.map(MemberNameAndDesc::fromMember)
).filter(m ->
(m.getModifiers() & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) != 0 &&
(m.getModifiers() & Opcodes.ACC_SYNTHETIC) == 0 &&
!m.isAnnotationPresent(CoverageIgnore.class) &&
!m.isAnnotationPresent(Stub.class) &&
!m.isAnnotationPresent(Modify.class) &&
!m.getName().startsWith("jvmdg$")
).map(MemberNameAndDesc::fromMember)
.map(m -> m.toFullyQualified(e.getValue().getFirst()))
).collect(Collectors.toSet());
var unmatchedStubs = versionProvider.stubMappings.values().stream().flatMap(value -> Stream.of(value.getMethodStubMap().values().stream(), value.getMethodModifyMap().values().stream()).flatMap(e -> e)).map(Pair::getFirst).collect(Collectors.toList());
Expand Down Expand Up @@ -226,7 +237,9 @@ public static void main(String[] args) throws IOException, URISyntaxException {
var unmatched = Path.of("./coverage/" + stubVersion + "/unmatched.txt");
writeList(
Stream.concat(
unmatchedStubs.stream().map(FullyQualifiedMemberNameAndDesc::of),
unmatchedStubs.stream()
.filter(e -> !e.isAnnotationPresent(CoverageIgnore.class))
.map(FullyQualifiedMemberNameAndDesc::of),
stubClassMethods.stream()
).map(e -> new MemberInfo("unknown", e, false, false))
.collect(Collectors.toList()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
public class J_L_I_MethodType {


// pkg-private -> public

@Stub
public static Class<?> lastParameterType(MethodType mt) {
if (mt.parameterCount() == 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package xyz.wagyourtail.jvmdg.j11.stub.java_net_http;

import xyz.wagyourtail.jvmdg.version.Adapter;
import xyz.wagyourtail.jvmdg.version.CoverageIgnore;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -17,6 +18,7 @@
public class J_N_H_HttpHeaders {
Map<String, List<String>> headers;

@CoverageIgnore
public J_N_H_HttpHeaders(Map<String, List<String>> headers) {
this.headers = headers;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ interface BodyHandler<T> {

@Adapter("Ljava/net/http/HttpResponse$BodyHandlers;")
class BodyHandlers {

private BodyHandlers() {}

private static Charset charsetFrom(J_N_H_HttpHeaders headers) {
// throw MissingStubError.create();
return StandardCharsets.UTF_8;
Expand Down Expand Up @@ -223,6 +226,8 @@ public static <T> BodyHandler<T> buffering(BodyHandler<T> downstream, int buffer
@Adapter("Ljava/net/http/HttpResponse$BodySubscribers;")
class BodySubscribers {

private BodySubscribers() {}

public static BodySubscriber<Void> fromSubscriber(Flow.Subscriber<? super List<ByteBuffer>> subscriber) {
return fromSubscriber(subscriber, (s) -> null);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package xyz.wagyourtail.jvmdg.j12.stub.java_base;

import xyz.wagyourtail.jvmdg.version.Adapter;
import xyz.wagyourtail.jvmdg.version.CoverageIgnore;

import java.lang.invoke.MethodHandles;
import java.util.Objects;
Expand Down Expand Up @@ -164,6 +165,7 @@ default String displayName() {
}

@Override
@CoverageIgnore // for generics
Class<?> resolveConstantDesc(MethodHandles.Lookup lookup) throws ReflectiveOperationException;

boolean equals(Object obj);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package xyz.wagyourtail.jvmdg.j12.stub.java_base;

import xyz.wagyourtail.jvmdg.version.CoverageIgnore;
import xyz.wagyourtail.jvmdg.version.Ref;
import xyz.wagyourtail.jvmdg.version.Stub;

Expand All @@ -13,6 +14,7 @@ public class J_N_F_FileSystems {

// fix env bug in older java

@CoverageIgnore
@Stub(ref = @Ref("java/nio/file/FileSystems"))
public static FileSystem newFileSystem(URI uri, Map<String, Object> env) throws IOException {
env.replaceAll((k, v) -> {
Expand All @@ -24,6 +26,7 @@ public static FileSystem newFileSystem(URI uri, Map<String, Object> env) throws
return FileSystems.newFileSystem(uri, env);
}

@CoverageIgnore
@Stub(ref = @Ref("java/nio/file/FileSystems"))
public static FileSystem newFileSystem(URI uri, Map<String, Object> env, ClassLoader loader) throws IOException {
env.replaceAll((k, v) -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package xyz.wagyourtail.jvmdg.j12.stub.java_base;

import xyz.wagyourtail.jvmdg.version.CoverageIgnore;
import xyz.wagyourtail.jvmdg.version.Stub;

import java.io.IOException;
Expand All @@ -12,6 +13,7 @@
public class J_N_F_S_FileSystemProvider {

@Stub
@CoverageIgnore
public static FileSystem newFileSystem(FileSystemProvider provider, URI uri, Map<String, Object> env) throws IOException {
env.replaceAll((k, v) -> {
if (v instanceof Boolean && !k.equals("useTempFile")) {
Expand All @@ -23,6 +25,7 @@ public static FileSystem newFileSystem(FileSystemProvider provider, URI uri, Map
}

@Stub
@CoverageIgnore
public static FileSystem newFileSystem(FileSystemProvider provider, Path path, Map<String, Object> env) throws IOException {
env.replaceAll((k, v) -> {
if (v instanceof Boolean && !k.equals("useTempFile")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@

public class J_I_PrintStream {

@Stub
public static void write(PrintStream stream, byte[] buf) {
stream.write(buf, 0, buf.length);
}

@Stub
public static void writeBytes(PrintStream stream, byte[] buf) {
stream.write(buf, 0, buf.length);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import xyz.wagyourtail.jvmdg.ClassDowngrader;
import xyz.wagyourtail.jvmdg.util.Function;
import xyz.wagyourtail.jvmdg.util.Utils;
import xyz.wagyourtail.jvmdg.version.Adapter;
import xyz.wagyourtail.jvmdg.version.Stub;

import java.lang.instrument.IllegalClassFormatException;
Expand Down Expand Up @@ -43,7 +44,7 @@ public static Class<?> ensureInitialized(MethodHandles.Lookup lookup, Class<?> c
}

@Stub(requiresRuntime = true)
public static Class<?> defineHiddenClass(MethodHandles.Lookup lookup, byte[] bytes, boolean initialize, J_L_I_MethodHandles$Lookup$ClassOption... options) throws IllegalClassFormatException {
public static Class<?> defineHiddenClass(MethodHandles.Lookup lookup, byte[] bytes, boolean initialize, ClassOption... options) throws IllegalClassFormatException {
Objects.requireNonNull(bytes);
Objects.requireNonNull(options);
HiddenClassLoader loader = new HiddenClassLoader(lookup.lookupClass().getClassLoader());
Expand Down Expand Up @@ -90,4 +91,15 @@ public byte[] apply(String s) {
}
}

@Adapter("Ljava/lang/invoke/MethodHandles$Lookup$ClassOption;")
public enum ClassOption {
NESTMATE(0x00000001),
STRONG(0x00000004);

private final int flag;

ClassOption(int flag) {
this.flag = flag;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class J_L_R_RecordComponent {
private final Field field;
private final Method accessor;

public J_L_R_RecordComponent(Class<?> declaring, String field, Class<?> type) {
J_L_R_RecordComponent(Class<?> declaring, String field, Class<?> type) {
this.declaring = declaring;

Field fd = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import xyz.wagyourtail.jvmdg.version.Adapter;
import xyz.wagyourtail.jvmdg.version.CoverageIgnore;
import xyz.wagyourtail.jvmdg.version.Stub;

import java.util.Objects;
Expand All @@ -20,6 +21,7 @@ public static DoubleStream mapMulti(DoubleStream stream, DoubleMapMultiConsumer
@Adapter("Ljava/util/stream/DoubleStream$DoubleMapMultiConsumer;")
public interface DoubleMapMultiConsumer {

@CoverageIgnore
default DoubleStream of(double d) {
DoubleStream.Builder doubles = DoubleStream.builder();
accept(d, doubles);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import xyz.wagyourtail.jvmdg.version.Adapter;
import xyz.wagyourtail.jvmdg.version.CoverageIgnore;
import xyz.wagyourtail.jvmdg.version.Stub;

import java.util.function.IntConsumer;
Expand All @@ -20,6 +21,7 @@ public static IntStream mapMulti(IntStream stream, IntMapMultiConsumer mapper) {
@Adapter("Ljava/util/stream/IntStream$IntMapMultiConsumer;")
public interface IntMapMultiConsumer {

@CoverageIgnore
default IntStream of(int d) {
IntStream.Builder integers = IntStream.builder();
accept(d, integers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import xyz.wagyourtail.jvmdg.version.Adapter;
import xyz.wagyourtail.jvmdg.version.CoverageIgnore;
import xyz.wagyourtail.jvmdg.version.Stub;

import java.util.function.LongConsumer;
Expand All @@ -21,6 +22,7 @@ public static LongStream mapMulti(LongStream stream, LongMapMultiConsumer mapper
@Adapter("Ljava/util/stream/LongStream$LongMapMultiConsumer;")
public interface LongMapMultiConsumer {

@CoverageIgnore
default LongStream of(long d) {
LongStream.Builder longs = LongStream.builder();
accept(d, longs);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package xyz.wagyourtail.jvmdg.j17.stub.java_base;

import xyz.wagyourtail.jvmdg.version.Adapter;
import xyz.wagyourtail.jvmdg.version.CoverageIgnore;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.CharBuffer;
import java.util.Objects;

@Adapter("java/util/HexFormat")
public record J_U_HexFormat(String delimiter, String prefix, String suffix, char[] digits) {
public record J_U_HexFormat(String delimiter, String prefix, String suffix, @CoverageIgnore char[] digits) {
@CoverageIgnore
public J_U_HexFormat {}

private static final char[] lowercase = "0123456789abcdef".toCharArray();
private static final char[] uppercase = "0123456789ABCDEF".toCharArray();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
@Adapter(value = "java/util/SequencedCollection", target = "java/util/Collection")
public class J_U_SequencedCollection {

private J_U_SequencedCollection() {
}

public static boolean jvmdg$instanceof(Object obj) {
return obj instanceof List<?> ||
obj instanceof LinkedHashSet<?> ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
@Adapter(value = "java/util/SequencedMap", target = "java/util/Map")
public class J_U_SequencedMap {

private J_U_SequencedMap() {
}

public static boolean jvmdg$instanceof(Object obj) {
return obj instanceof LinkedHashMap<?, ?> ||
obj instanceof SortedMap<?, ?> ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import xyz.wagyourtail.jvmdg.j21.impl.ReverseSet;
import xyz.wagyourtail.jvmdg.version.Adapter;
import xyz.wagyourtail.jvmdg.version.Ref;
import xyz.wagyourtail.jvmdg.version.Stub;

import java.util.LinkedHashSet;
import java.util.Set;
Expand All @@ -10,6 +12,9 @@
@Adapter(value = "java/util/SequencedSet", target = "java/util/Set")
public class J_U_SequencedSet {

private J_U_SequencedSet() {
}

public static boolean jvmdg$instanceof(Object obj) {
return obj instanceof LinkedHashSet<?> ||
obj instanceof SortedSet<?> ||
Expand All @@ -26,6 +31,7 @@ public class J_U_SequencedSet {
throw new ClassCastException();
}

@Stub
public static <E> Set<E> reversed(Set<E> self) {
if (self instanceof ReverseSet<E> rs) {
return rs.original;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@


import xyz.wagyourtail.jvmdg.version.Adapter;
import xyz.wagyourtail.jvmdg.version.CoverageIgnore;

@Adapter("Ljava/lang/Module;")
public class J_L_Module {

private final ClassLoader classLoader;
private final J_L_ModuleLayer layer = new J_L_ModuleLayer();

@CoverageIgnore
public J_L_Module() {
J_L_StackWalker walker = J_L_StackWalker.getInstance(J_L_StackWalker.Option.RETAIN_CLASS_REFERENCE);
J_L_StackWalker.StackFrame sf = walker.walk(stream -> stream.skip(2).findFirst().get());
Expand All @@ -19,6 +21,7 @@ public J_L_Module() {
this.classLoader = sf.getDeclaringClass().getClassLoader();
}

@CoverageIgnore
public J_L_Module(ClassLoader classLoader) {
this.classLoader = classLoader;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
@Adapter("java/util/concurrent/Flow")
public class J_U_C_Flow {

private J_U_C_Flow() {
}

public static int defaultBufferSize() {
return 256;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void init() {
// ConstantDescs
// ConstantBootstraps
stub(J_L_I_MethodHandles$Lookup.class);
stub(J_L_I_MethodHandles$Lookup$ClassOption.class);
stub(J_L_I_MethodHandles$Lookup.ClassOption.class);
stub(J_N_C_ServerSocketChannel.class);
stub(J_N_C_SocketChannel.class);
// EdECKey
Expand Down
Loading

0 comments on commit e668a0d

Please sign in to comment.