Skip to content

Commit

Permalink
Remove now unused code and make use of new language features
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytv committed Mar 24, 2024
1 parent c3fec17 commit 2f5c21c
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 102 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/minecraftforge/fart/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private static String[] expandArgs(String[] args) throws IOException {
}
}

return ret.toArray(new String[ret.size()]);
return ret.toArray(new String[0]);
}

private static String getVersion() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ public <O> List<O> invokeAll(Collection<Pair<String, ? extends Callable<O>>> tas
List<O> ret = new ArrayList<>(tasks.size());
List<Pair<String, Future<O>>> processed = new ArrayList<>(tasks.size());
for (Pair<String, ? extends Callable<O>> task : tasks) {
processed.add(new Pair<>(task.getLeft(), exec.submit(task.getRight())));
processed.add(new Pair<>(task.left(), exec.submit(task.right())));
}
for (Pair<String, Future<O>> future : processed) {
try {
O done = future.getRight().get();
O done = future.right().get();
if (done != null)
ret.add(done);
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException("Failed to execute task " + future.getLeft(), e);
throw new RuntimeException("Failed to execute task " + future.left(), e);
}
}
return ret;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ static class ClassInfo implements IClassInfo {
this.name = Util.nameToBytecode(node);
this.access = new Access(node.getModifiers());
this.superName = Util.nameToBytecode(node.getSuperclass());
this.interfaces = Collections.unmodifiableList(Arrays.stream(node.getInterfaces())
.map(c -> Util.nameToBytecode(c)).collect(Collectors.toList()));
this.interfaces = Arrays.stream(node.getInterfaces()).map(Util::nameToBytecode).toList();

Map<String, MethodInfo> mtds = Stream.concat(
Arrays.stream(node.getConstructors()).map(MethodInfo::new),
Expand All @@ -142,7 +141,7 @@ static class ClassInfo implements IClassInfo {

Field[] flds = node.getDeclaredFields();
if (flds != null && flds.length > 0) {
this.fields = Collections.unmodifiableMap(Arrays.asList(flds).stream().map(FieldInfo::new)
this.fields = Collections.unmodifiableMap(Arrays.stream(flds).map(FieldInfo::new)
.collect(Collectors.toMap(FieldInfo::getName, Function.identity())));
} else
this.fields = null;
Expand Down Expand Up @@ -346,7 +345,7 @@ public String toString() {
if (ret.isEmpty())
toString = "default";
else
toString = ret.stream().collect(Collectors.joining(" "));
toString = String.join(" ", ret);
}
return toString;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,8 @@ public String mapParameterName(final String owner, final String methodName, fina

@Override
public Object mapValue(final Object value) {
if (value instanceof Handle) {
if (value instanceof Handle handle) {
// Backport of ASM!327 https://gitlab.ow2.org/asm/asm/-/merge_requests/327
final Handle handle = (Handle) value;
final boolean isFieldHandle = handle.getTag() <= Opcodes.H_PUTSTATIC;

return new Handle(
Expand Down Expand Up @@ -410,7 +409,7 @@ public class MMethod {
tmp.add(name);
}

this.params = tmp.toArray(new String[tmp.size()]);
this.params = tmp.toArray(new String[0]);
} else {
this.params = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,18 @@ static String getJavadocDesc(Type type) {
}

static String getJavadocType(Type type) {
switch (type.getSort()) {
case BOOLEAN: return "boolean";
case INT: return "int";
case LONG: return "long";
case DOUBLE: return "double";
case FLOAT: return "float";
case CHAR: return "char";
case SHORT: return "short";
case BYTE: return "byte";
case OBJECT: return type.getInternalName().replace('/', '.');
case ARRAY: return getJavadocType(type.getElementType()) + "[]";
default:
throw new UnsupportedOperationException("Unknown type in javadoc: " + type.getSort());
}
return switch (type.getSort()) {
case BOOLEAN -> "boolean";
case INT -> "int";
case LONG -> "long";
case DOUBLE -> "double";
case FLOAT -> "float";
case CHAR -> "char";
case SHORT -> "short";
case BYTE -> "byte";
case OBJECT -> type.getInternalName().replace('/', '.');
case ARRAY -> getJavadocType(type.getElementType()) + "[]";
default -> throw new UnsupportedOperationException("Unknown type in javadoc: " + type.getSort());
};
}
}
17 changes: 1 addition & 16 deletions src/main/java/net/minecraftforge/fart/internal/Pair.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,5 @@

package net.minecraftforge.fart.internal;

class Pair<L, R> {
private final L left;
private final R right;

Pair(L left, R right) {
this.left = left;
this.right = right;
}

public L getLeft() {
return left;
}

public R getRight() {
return right;
}
record Pair<L, R>(L left, R right) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,6 @@ public void visitEnd() {
}
}

private static class AnnotationHolder {
final int parameter;
final String descriptor;
final boolean visible;
final AnnotationNode node;

AnnotationHolder(int parameter, String descriptor, boolean visible, AnnotationNode node) {
this.parameter = parameter;
this.descriptor = descriptor;
this.visible = visible;
this.node = node;
}
private record AnnotationHolder(int parameter, String descriptor, boolean visible, AnnotationNode node) {
}
}
14 changes: 3 additions & 11 deletions src/main/java/net/minecraftforge/fart/internal/RecordFixer.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public FieldVisitor visitField(int access, String name, String descriptor, Strin
}
// Manually add the record component back if this class doesn't have any
if (components == null)
components = new LinkedHashMap<String, Entry>();
components = new LinkedHashMap<>();
components.put(name + descriptor, new Entry(name, descriptor, signature));
}
return super.visitField(access, name, descriptor, signature, value);
Expand All @@ -74,19 +74,11 @@ public void visitEnd() {
}
}

private static class Entry {
private final String name;
private final String descriptor;
private final String signature;
private Entry(String name, String descriptor, String signature) {
this.name = name;
this.descriptor = descriptor;
this.signature = signature;
}
private record Entry(String name, String descriptor, String signature) {

@Override
public String toString() {
return "[Name: " + name + ", Desc: " + descriptor + ", Sig: " + signature + "]";
return "[Name: " + name + ", Desc: " + descriptor + ", Sig: " + signature + "]";
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ else if (name.equals("javadoctor.json"))

// We care about stable output, so sort, and single thread write.
logger.accept("Sorting");
Collections.sort(newEntries, this::compare);
newEntries.sort(this::compare);

if (!output.getParentFile().exists())
output.getParentFile().mkdirs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@ public Collection<? extends Entry> getExtras() {
}

void storeNames(String className, String methodName, String methodDescriptor, Collection<String> paramNames) {
abstractParams.add(className + ' ' + methodName + ' ' + methodDescriptor + ' ' + paramNames.stream().collect(Collectors.joining(" ")));
abstractParams.add(className + ' ' + methodName + ' ' + methodDescriptor + ' ' + String.join(" ", paramNames));
}
}
36 changes: 0 additions & 36 deletions src/main/java/net/minecraftforge/fart/internal/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,7 @@

package net.minecraftforge.fart.internal;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

class Util {
public static void forZip(ZipFile zip, IOConsumer<ZipEntry> consumer) throws IOException {
for (Enumeration<? extends ZipEntry> entries = zip.entries(); entries.hasMoreElements();) {
consumer.accept(entries.nextElement());
}
}

@FunctionalInterface
public static interface IOConsumer<T> {
public void accept(T value) throws IOException;
}

public static byte[] toByteArray(InputStream input) throws IOException {
return toByteArray(input, -1);
}

public static byte[] toByteArray(InputStream input, int initialStreamSize) throws IOException {
ByteArrayOutputStream output = initialStreamSize > 0 ? new ByteArrayOutputStream(initialStreamSize) : new ByteArrayOutputStream();
copy(input, output);
return output.toByteArray();
}

public static void copy(InputStream input, OutputStream output) throws IOException {
byte[] buf = new byte[2048];
int cnt = 0;
while ((cnt = input.read(buf, 0, buf.length)) != -1) {
output.write(buf, 0, cnt);
}
}

public static String nameToBytecode(Class<?> cls) {
return cls == null ? null : cls.getName().replace('.', '/');
Expand Down

0 comments on commit 2f5c21c

Please sign in to comment.