Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion codebook-cli/src/main/java/io/papermc/codebook/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,10 @@ private CodeBookContext createContext() {
}

private record Coords(
@Nullable String coords, @Nullable String classifier, @Nullable String extension, String baseUrl) {}
@Nullable String coords,
@Nullable String classifier,
@Nullable String extension,
String baseUrl) {}

private void verifyFileExists(final String name, final Path file) {
if (!Files.isRegularFile(file)) {
Expand Down
11 changes: 6 additions & 5 deletions codebook-lvt/src/main/java/io/papermc/codebook/lvt/LvtNamer.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
import dev.denwav.hypo.model.data.FieldData;
import dev.denwav.hypo.model.data.HypoKey;
import dev.denwav.hypo.model.data.MethodData;
import dev.denwav.hypo.model.data.types.JvmType;
import dev.denwav.hypo.model.data.types.PrimitiveType;
import dev.denwav.hypo.types.PrimitiveType;
import dev.denwav.hypo.types.desc.TypeDescriptor;
import io.papermc.codebook.report.ReportType;
import io.papermc.codebook.report.Reports;
import io.papermc.codebook.report.type.MissingMethodParam;
Expand Down Expand Up @@ -208,7 +208,8 @@ private void fillNames0(final MethodData method) throws IOException {
if (node.localVariables == null) {
// interface / abstract methods don't have LVT
// But we still need to set param names
final List<JvmType> paramTypes = method.descriptor().getParams();
final List<? extends TypeDescriptor> paramTypes =
method.descriptor().getParameters();
final int paramCount = paramTypes.size();

if (node.parameters == null) {
Expand Down Expand Up @@ -468,7 +469,7 @@ private static int fromLvtToParamIndex(final int lvtIndex, final MethodData meth
int currentIndex = 0;
int currentLvtIndex = method.isStatic() ? 0 : 1;

for (final JvmType param : method.params()) {
for (final TypeDescriptor param : method.params()) {
if (currentLvtIndex == lvtIndex) {
return currentIndex;
}
Expand All @@ -490,7 +491,7 @@ private static int fromParamToLvtIndex(final int paramIndex, final MethodData me
int currentLvtIndex = method.isStatic() ? 0 : 1;
int currentParamIndex = 0;

for (final JvmType param : method.params()) {
for (final TypeDescriptor param : method.params()) {
if (currentParamIndex == paramIndex) {
return currentLvtIndex;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
import com.google.common.base.Splitter;
import dev.denwav.hypo.core.HypoContext;
import dev.denwav.hypo.model.data.ClassData;
import dev.denwav.hypo.model.data.types.ArrayType;
import dev.denwav.hypo.model.data.types.ClassType;
import dev.denwav.hypo.model.data.types.JvmType;
import dev.denwav.hypo.model.data.types.PrimitiveType;
import dev.denwav.hypo.types.PrimitiveType;
import dev.denwav.hypo.types.desc.ArrayTypeDescriptor;
import dev.denwav.hypo.types.desc.ClassTypeDescriptor;
import dev.denwav.hypo.types.desc.TypeDescriptor;
import java.io.IOException;
import java.util.List;
import java.util.Objects;
Expand All @@ -54,45 +54,43 @@ public LvtTypeSuggester(final HypoContext context) throws IOException {
this.mapClass = Objects.requireNonNull(map, "java/util/Map not found");
}

public String suggestNameFromType(final JvmType type) throws IOException {
if (type instanceof PrimitiveType) {
return switch ((PrimitiveType) type) {
case CHAR -> "c";
case BYTE -> "b";
case SHORT -> "s";
case INT -> "i";
case LONG -> "l";
case FLOAT -> "f";
case DOUBLE -> "d";
case BOOLEAN -> "flag";
case VOID -> throw new IllegalStateException("Illegal local variable type: " + type);
};
} else if (type instanceof ClassType) {
return this.suggestNameFromClassType((ClassType) type);
} else if (type instanceof ArrayType) {
final JvmType baseType = ((ArrayType) type).baseType();
if (baseType instanceof PrimitiveType) {
return switch (((PrimitiveType) baseType)) {
case CHAR -> "chars";
case BYTE -> "bytes";
case SHORT -> "shorts";
case INT -> "ints";
case LONG -> "longs";
case FLOAT -> "floats";
case DOUBLE -> "doubles";
case BOOLEAN -> "flags";
case VOID -> throw new IllegalStateException("Illegal local variable type: " + type);
public String suggestNameFromType(final TypeDescriptor type) throws IOException {
return switch (type) {
case final PrimitiveType primitiveType ->
switch (primitiveType) {
case CHAR -> "c";
case BYTE -> "b";
case SHORT -> "s";
case INT -> "i";
case LONG -> "l";
case FLOAT -> "f";
case DOUBLE -> "d";
case BOOLEAN -> "flag";
};
} else {
return this.suggestNameFromType(baseType) + "s";
case final ClassTypeDescriptor classType -> this.suggestNameFromClassType(classType);
case final ArrayTypeDescriptor arrayType -> {
final TypeDescriptor baseType = arrayType.getBaseType();
if (baseType instanceof PrimitiveType) {
yield switch (((PrimitiveType) baseType)) {
case CHAR -> "chars";
case BYTE -> "bytes";
case SHORT -> "shorts";
case INT -> "ints";
case LONG -> "longs";
case FLOAT -> "floats";
case DOUBLE -> "doubles";
case BOOLEAN -> "flags";
};
} else {
yield this.suggestNameFromType(baseType) + "s";
}
}
} else {
throw new IllegalStateException("Unknown type: " + type);
}
case null, default -> throw new IllegalStateException("Unknown type: " + type);
};
}

private String suggestNameFromClassType(final ClassType type) throws IOException {
final String name = type.asInternalName();
private String suggestNameFromClassType(final ClassTypeDescriptor type) throws IOException {
final String name = type.asInternal();
if (name.equals("Ljava/lang/String;")) {
return "string";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
package io.papermc.codebook.lvt;

import dev.denwav.hypo.asm.HypoAsmUtil;
import dev.denwav.hypo.model.data.types.JvmType;
import dev.denwav.hypo.types.desc.TypeDescriptor;
import java.util.List;
import java.util.Locale;
import java.util.function.Predicate;
Expand All @@ -36,7 +36,7 @@ public final class LvtUtil {

private LvtUtil() {}

public static JvmType toJvmType(final String desc) {
public static TypeDescriptor toJvmType(final String desc) {
return HypoAsmUtil.toJvmType(Type.getType(desc));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@

package io.papermc.codebook.lvt;

import static dev.denwav.hypo.model.data.MethodDescriptor.parseDescriptor;
import static io.papermc.codebook.lvt.LvtUtil.toJvmType;

import com.google.inject.AbstractModule;
import com.google.inject.Injector;
import dev.denwav.hypo.core.HypoContext;
import dev.denwav.hypo.model.data.ClassData;
import dev.denwav.hypo.model.data.MethodData;
import dev.denwav.hypo.model.data.MethodDescriptor;
import dev.denwav.hypo.model.data.types.JvmType;
import dev.denwav.hypo.types.desc.MethodDescriptor;
import dev.denwav.hypo.types.desc.TypeDescriptor;
import io.papermc.codebook.lvt.suggestion.ComplexGetSuggester;
import io.papermc.codebook.lvt.suggestion.FluentGetterSuggester;
import io.papermc.codebook.lvt.suggestion.GenericSuggester;
Expand Down Expand Up @@ -146,7 +145,7 @@ public String suggestName(
}

// we couldn't determine a name from the assignment, so determine a name from the type
final JvmType lvtType = toJvmType(lvt.desc);
final TypeDescriptor lvtType = toJvmType(lvt.desc);
return determineFinalName(this.lvtTypeSuggester.suggestNameFromType(lvtType), scopedNames);
}

Expand Down Expand Up @@ -231,7 +230,7 @@ boolean is(final MethodInsnNode node) {
return null;
}
final @Nullable MethodData method =
findMethod(owner, methodInsnNode.name, parseDescriptor(methodInsnNode.desc));
findMethod(owner, methodInsnNode.name, MethodDescriptor.parse(methodInsnNode.desc));
if (method == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ public class ComplexGetSuggester implements LvtSuggester {
}

private record StaticFieldEntry(
Set<String> owners, Set<Entry<String, String>> methods, Set<String> fieldTypes, @Nullable String suffix) {
Set<String> owners,
Set<Entry<String, String>> methods,
Set<String> fieldTypes,
@Nullable String suffix) {

boolean test(final MethodInsnNode node) {
return this.owners.contains(node.owner)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

package io.papermc.codebook.lvt.suggestion;

import dev.denwav.hypo.model.data.types.PrimitiveType;
import dev.denwav.hypo.types.PrimitiveType;
import io.papermc.codebook.lvt.suggestion.context.ContainerContext;
import io.papermc.codebook.lvt.suggestion.context.method.MethodCallContext;
import io.papermc.codebook.lvt.suggestion.context.method.MethodInsnContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import static java.util.Objects.requireNonNull;

import dev.denwav.hypo.model.data.MethodData;
import dev.denwav.hypo.model.data.types.PrimitiveType;
import dev.denwav.hypo.types.PrimitiveType;
import io.papermc.codebook.lvt.suggestion.context.ContainerContext;
import io.papermc.codebook.lvt.suggestion.context.method.MethodCallContext;
import io.papermc.codebook.lvt.suggestion.context.method.MethodInsnContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@

import dev.denwav.hypo.core.HypoContext;
import dev.denwav.hypo.model.data.MemberData;
import dev.denwav.hypo.model.data.types.JvmType;
import dev.denwav.hypo.model.data.types.PrimitiveType;
import dev.denwav.hypo.types.PrimitiveType;
import dev.denwav.hypo.types.desc.TypeDescriptor;
import io.papermc.codebook.lvt.LvtTypeSuggester;
import io.papermc.codebook.lvt.suggestion.context.ContainerContext;
import io.papermc.codebook.lvt.suggestion.context.method.MethodCallContext;
Expand Down Expand Up @@ -73,11 +73,11 @@ public class SingleVerbBooleanSuggester implements LvtSuggester {
return null;
}

final List<JvmType> paramTypes = call.data().params();
final List<? extends TypeDescriptor> paramTypes = call.data().params();
if (paramTypes.size() != 1) {
return null;
}
final String paramTypeDesc = paramTypes.get(0).asInternalName();
final String paramTypeDesc = paramTypes.get(0).asInternal();

final AbstractInsnNode prev = insn.node().getPrevious();
if (prev instanceof final FieldInsnNode fieldInsnNode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public class StringSuggester implements LvtSuggester {
}
}

if (methodName.equals("repeat")
&& call.data().returnType().asInternalName().equals("Ljava/lang/String;")) {
if (methodName.equals("repeat") && call.data().returnType().asInternal().equals("Ljava/lang/String;")) {
return "repeated";
}
if (methodName.equals("indexOf") || methodName.equals("lastIndexOf")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import static io.papermc.codebook.lvt.LvtUtil.tryMatchPrefix;

import dev.denwav.hypo.model.data.types.PrimitiveType;
import dev.denwav.hypo.types.PrimitiveType;
import io.papermc.codebook.lvt.suggestion.context.ContainerContext;
import io.papermc.codebook.lvt.suggestion.context.method.MethodCallContext;
import io.papermc.codebook.lvt.suggestion.context.method.MethodInsnContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import static io.papermc.codebook.lvt.LvtUtil.hasPrefix;
import static io.papermc.codebook.lvt.suggestion.numbers.RandomUtil.createNextRandomName;

import dev.denwav.hypo.model.data.types.JvmType;
import dev.denwav.hypo.types.desc.TypeDescriptor;
import io.papermc.codebook.lvt.suggestion.LvtSuggester;
import io.papermc.codebook.lvt.suggestion.context.ContainerContext;
import io.papermc.codebook.lvt.suggestion.context.method.MethodCallContext;
Expand All @@ -50,7 +50,7 @@ public class MthRandomSuggester implements LvtSuggester {
return null;
}

final List<JvmType> params = call.data().params();
final List<? extends TypeDescriptor> params = call.data().params();
if (params.isEmpty() || !params.get(0).equals(RandomSourceSuggester.RANDOM_SOURCE_TYPE)) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

import dev.denwav.hypo.core.HypoContext;
import dev.denwav.hypo.model.data.ClassData;
import dev.denwav.hypo.model.data.types.ClassType;
import dev.denwav.hypo.model.data.types.JvmType;
import dev.denwav.hypo.types.desc.ClassTypeDescriptor;
import dev.denwav.hypo.types.desc.TypeDescriptor;
import io.papermc.codebook.lvt.suggestion.LvtSuggester;
import io.papermc.codebook.lvt.suggestion.context.ContainerContext;
import io.papermc.codebook.lvt.suggestion.context.method.MethodCallContext;
Expand All @@ -39,7 +39,7 @@
// primitive methods in RandomSource
public class RandomSourceSuggester implements LvtSuggester {

static final JvmType RANDOM_SOURCE_TYPE = new ClassType("net/minecraft/util/RandomSource");
static final TypeDescriptor RANDOM_SOURCE_TYPE = ClassTypeDescriptor.of("net/minecraft/util/RandomSource");

private final @Nullable ClassData randomSourceClass;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import static io.papermc.codebook.lvt.LvtUtil.findNextWord;

import dev.denwav.hypo.model.data.MethodData;
import dev.denwav.hypo.model.data.types.PrimitiveType;
import dev.denwav.hypo.types.PrimitiveType;
import java.util.function.Predicate;
import org.checkerframework.checker.nullness.qual.Nullable;

Expand Down
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
spotless = "8.0.0"
palantir = "2.50.0"
spotless = "8.8.0"
palantir = "2.96.0"
indra = "4.0.0"
slf4j = "2.0.7"
lorenz = "0.5.7"
Expand Down Expand Up @@ -42,7 +42,7 @@ asm-tree = { module = "org.ow2.asm:asm-tree", version.ref = "asm" }
unpick-format = { module = "io.papermc.unpick:unpick-format-utils", version.ref = "unpick" }
unpick = { module = "io.papermc.unpick:unpick", version.ref = "unpick" }

hypo-platform = "dev.denwav.hypo:hypo-platform:2.4.1"
hypo-platform = "dev.denwav.hypo:hypo-platform:3.0.0"
hypo-model = { module = "dev.denwav.hypo:hypo-model" }
hypo-core = { module = "dev.denwav.hypo:hypo-core" }
hypo-asm = { module = "dev.denwav.hypo:hypo-asm" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@
import io.soabase.recordbuilder.core.RecordBuilder;
import java.nio.file.Path;
import java.util.List;
import org.jetbrains.annotations.NotNull;

@RecordBuilder
@RecordBuilder.Options(interpretNotNulls = true, addSingleItemCollectionBuilders = true, useImmutableCollections = true)
public record CodeBookJarInput(@NotNull Path inputJar, @NotNull List<Path> classpathJars) implements CodeBookInput {
public record CodeBookJarInput(Path inputJar, List<Path> classpathJars) implements CodeBookInput {

static CodeBookJarInputBuilder builder() {
return CodeBookJarInputBuilder.builder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
import java.net.URI;
import java.nio.file.Path;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.jetbrains.annotations.NotNull;

@RecordBuilder
@RecordBuilder.Options(interpretNotNulls = true)
public record CodeBookUriResource(
@NotNull String name, @NotNull URI uri, @Nullable @org.jetbrains.annotations.Nullable String sha1)
implements CodeBookResource, DownloadSpec {
String name,
URI uri,
@Nullable @org.jetbrains.annotations.Nullable String sha1) implements CodeBookResource, DownloadSpec {

public static CodeBookUriResourceBuilder builder() {
return CodeBookUriResourceBuilder.builder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@
import io.papermc.codebook.util.DownloadSpec;
import java.net.URI;

public record MinecraftVersionDownload(String sha1, @SerializedName("url") URI uri) implements DownloadSpec {}
public record MinecraftVersionDownload(
String sha1, @SerializedName("url") URI uri) implements DownloadSpec {}
Loading