Skip to content

Commit

Permalink
optimize imports, reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
wagyourtail committed Apr 13, 2024
1 parent b0fa44d commit b828a85
Show file tree
Hide file tree
Showing 203 changed files with 1,189 additions and 1,227 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build_snapshot.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

name: Build Snapshot

on:
Expand Down
50 changes: 25 additions & 25 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,28 +165,28 @@ fee.
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:

a) The modified work must itself be a software library.
a) The modified work must itself be a software library.

b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.

c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.

d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.

(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)

These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
Expand Down Expand Up @@ -338,14 +338,14 @@ distribute.
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:

a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.

b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.

8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# JvmDowngrader

downgrades modern java bytecode to older versions. at either compile and/or runtime (requires runtime for certain things to work such as `MethodHandles$Lookup#defineClass`).
downgrades modern java bytecode to older versions. at either compile and/or runtime (requires runtime for certain things
to work such as `MethodHandles$Lookup#defineClass`).

## initial relesase TODO:

- [ ] finish downgrade task for gradle plugin
- [ ] stub for MethodHandles$Lookup#defineClass



### inspired by

https://github.com/Chocohead/Not-So-New and https://github.com/luontola/retrolambda
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

public class TestFile {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

import java.io.IOException;
import java.io.UncheckedIOException;
import java.lang.reflect.Method;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
Expand Down Expand Up @@ -92,7 +90,8 @@ public static void main(String[] args) throws IOException, URISyntaxException {
compare(versions.get(v), classes, requiredStubs);
Map<Type, Class<?>> stubClasses = versionProvider.classStubs;

outer:for (var staticAndStub : requiredStubs) {
outer:
for (var staticAndStub : requiredStubs) {
var isStatic = staticAndStub.isStatic();
var isAbstract = staticAndStub.isAbstract();
var modName = staticAndStub.module();
Expand Down Expand Up @@ -205,8 +204,6 @@ public static void main(String[] args) throws IOException, URISyntaxException {
}
}

public record MemberInfo(String module, FullyQualifiedMemberNameAndDesc fqm, boolean isAbstract, boolean isStatic) {}

private static void writeList(List<MemberInfo> missing, Path outputFile) throws IOException {
Files.createDirectories(outputFile.getParent());
Files.deleteIfExists(outputFile);
Expand Down Expand Up @@ -282,7 +279,8 @@ public static void compare(List<Path> moduleHolders, Map<String, Pair<String, Cl
var oldCls = old.getSecond();
var methods = new HashSet<MemberInfo>();
var ct = Type.getObjectType(cn.name);
outerA:for (var m : oldCls.methods) {
outerA:
for (var m : oldCls.methods) {
if ((m.access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) == 0) continue;
if (m.name.equals("<clinit>")) continue;
if (m.invisibleAnnotations != null) {
Expand All @@ -297,7 +295,8 @@ public static void compare(List<Path> moduleHolders, Map<String, Pair<String, Cl
var fqn = new FullyQualifiedMemberNameAndDesc(ct, m.name, Type.getMethodType(m.desc));
methods.add(new MemberInfo(modName, fqn, isAbstract, isStatic));
}
outerB:for (var m : cn.methods) {
outerB:
for (var m : cn.methods) {
// is preview feature?
if (m.invisibleAnnotations != null) {
for (var a : m.invisibleAnnotations) {
Expand Down Expand Up @@ -373,4 +372,7 @@ public static void compare(List<Path> moduleHolders, Map<String, Pair<String, Cl
currentVersion.putAll(newClasses);
}

public record MemberInfo(String module, FullyQualifiedMemberNameAndDesc fqm, boolean isAbstract, boolean isStatic) {
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package xyz.wagyourtail.jvmdg.j10.stub.java_base;


import org.objectweb.asm.Opcodes;
import xyz.wagyourtail.jvmdg.version.Ref;
import xyz.wagyourtail.jvmdg.version.Stub;

import java.io.*;
import java.io.BufferedWriter;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.charset.Charset;

public class J_I_PrintWriter {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package xyz.wagyourtail.jvmdg.j10.stub.java_base;


import org.objectweb.asm.Opcodes;
import xyz.wagyourtail.jvmdg.version.Stub;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package xyz.wagyourtail.jvmdg.j10.stub.java_base;


import org.objectweb.asm.Opcodes;
import xyz.wagyourtail.jvmdg.version.Stub;

import java.lang.invoke.MethodType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package xyz.wagyourtail.jvmdg.j10.stub.java_base;


import org.objectweb.asm.Opcodes;
import xyz.wagyourtail.jvmdg.version.Stub;

public class J_L_Runtime$Version {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package xyz.wagyourtail.jvmdg.j10.stub.java_base;


import org.objectweb.asm.Opcodes;
import xyz.wagyourtail.jvmdg.version.Ref;
import xyz.wagyourtail.jvmdg.version.Stub;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package xyz.wagyourtail.jvmdg.j10.stub.java_base;


import org.objectweb.asm.Opcodes;
import xyz.wagyourtail.jvmdg.version.Ref;
import xyz.wagyourtail.jvmdg.version.Stub;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package xyz.wagyourtail.jvmdg.j10.stub.java_base;


import org.objectweb.asm.Opcodes;
import xyz.wagyourtail.jvmdg.version.Ref;
import xyz.wagyourtail.jvmdg.version.Stub;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package xyz.wagyourtail.jvmdg.j10.stub.java_base;


import org.objectweb.asm.Opcodes;
import xyz.wagyourtail.jvmdg.version.Ref;
import xyz.wagyourtail.jvmdg.version.Stub;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package xyz.wagyourtail.jvmdg.j10.stub.java_base;


import org.objectweb.asm.Opcodes;
import xyz.wagyourtail.jvmdg.version.Stub;

import java.util.NoSuchElementException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package xyz.wagyourtail.jvmdg.j10.stub.java_base;


import org.objectweb.asm.Opcodes;
import xyz.wagyourtail.jvmdg.version.Stub;

import java.util.NoSuchElementException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package xyz.wagyourtail.jvmdg.j10.stub.java_base;


import org.objectweb.asm.Opcodes;
import xyz.wagyourtail.jvmdg.version.Stub;

import java.util.NoSuchElementException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package xyz.wagyourtail.jvmdg.j10.stub.java_base;


import org.objectweb.asm.Opcodes;
import xyz.wagyourtail.jvmdg.version.Stub;

import java.util.NoSuchElementException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package xyz.wagyourtail.jvmdg.j10.stub.java_base;


import org.objectweb.asm.Opcodes;
import xyz.wagyourtail.jvmdg.version.Ref;
import xyz.wagyourtail.jvmdg.version.Stub;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package xyz.wagyourtail.jvmdg.j10.stub.java_base;


import org.objectweb.asm.Opcodes;
import xyz.wagyourtail.jvmdg.version.Ref;
import xyz.wagyourtail.jvmdg.version.Stub;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package xyz.wagyourtail.jvmdg.j11.stub.java_base;

import org.objectweb.asm.Opcodes;
import xyz.wagyourtail.jvmdg.version.Stub;

import java.io.ByteArrayOutputStream;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package xyz.wagyourtail.jvmdg.j11.stub.java_base;


import org.objectweb.asm.Opcodes;
import xyz.wagyourtail.jvmdg.version.Adapter;
import xyz.wagyourtail.jvmdg.version.Ref;
import xyz.wagyourtail.jvmdg.version.Stub;

import java.io.*;
import java.nio.charset.Charset;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package xyz.wagyourtail.jvmdg.j11.stub.java_base;


import org.objectweb.asm.Opcodes;
import xyz.wagyourtail.jvmdg.version.Adapter;
import xyz.wagyourtail.jvmdg.version.Ref;
import xyz.wagyourtail.jvmdg.version.Stub;

import java.io.*;
import java.nio.charset.Charset;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package xyz.wagyourtail.jvmdg.j11.stub.java_base;


import org.objectweb.asm.Opcodes;
import xyz.wagyourtail.jvmdg.version.Ref;
import xyz.wagyourtail.jvmdg.version.Stub;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package xyz.wagyourtail.jvmdg.j11.stub.java_base;


import org.objectweb.asm.Opcodes;
import xyz.wagyourtail.jvmdg.version.Ref;
import xyz.wagyourtail.jvmdg.version.Stub;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package xyz.wagyourtail.jvmdg.j11.stub.java_base;


import org.objectweb.asm.Opcodes;
import xyz.wagyourtail.jvmdg.version.Ref;
import xyz.wagyourtail.jvmdg.version.Stub;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package xyz.wagyourtail.jvmdg.j11.stub.java_base;


import org.objectweb.asm.Opcodes;
import xyz.wagyourtail.jvmdg.version.Ref;
import xyz.wagyourtail.jvmdg.version.Stub;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package xyz.wagyourtail.jvmdg.j11.stub.java_base;


import org.objectweb.asm.Opcodes;
import xyz.wagyourtail.jvmdg.version.Ref;
import xyz.wagyourtail.jvmdg.version.Stub;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package xyz.wagyourtail.jvmdg.j11.stub.java_base;

import org.objectweb.asm.Opcodes;
import xyz.wagyourtail.jvmdg.version.Ref;
import xyz.wagyourtail.jvmdg.version.Stub;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package xyz.wagyourtail.jvmdg.j11.stub.java_base;

import org.objectweb.asm.Opcodes;
import xyz.wagyourtail.jvmdg.version.Stub;

import java.lang.reflect.Field;
Expand Down Expand Up @@ -38,7 +37,7 @@ public static boolean isNestmateOf(Class<?> host, Class<?> clazz) throws ClassNo
@Stub
public static Class<?>[] getNestMembers(Class<?> clazz) throws IllegalAccessException, ClassNotFoundException {
if (clazz.isPrimitive() || clazz.isArray()) {
return new Class<?>[] { clazz };
return new Class<?>[]{clazz};
}
try {
Class<?> host = getNestHost(clazz);
Expand All @@ -51,7 +50,7 @@ public static Class<?>[] getNestMembers(Class<?> clazz) throws IllegalAccessExce
}
return classes;
} catch (NoSuchFieldException e) {
return new Class<?>[] { clazz };
return new Class<?>[]{clazz};
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package xyz.wagyourtail.jvmdg.j11.stub.java_base;


import org.objectweb.asm.Opcodes;
import xyz.wagyourtail.jvmdg.version.Stub;

import java.io.BufferedReader;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package xyz.wagyourtail.jvmdg.j11.stub.java_base;


import org.objectweb.asm.Opcodes;
import xyz.wagyourtail.jvmdg.version.Stub;

public class J_L_StringBuffer {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package xyz.wagyourtail.jvmdg.j11.stub.java_base;


import org.objectweb.asm.Opcodes;
import xyz.wagyourtail.jvmdg.version.Stub;

public class J_L_StringBuilder {
Expand Down
Loading

0 comments on commit b828a85

Please sign in to comment.