From 53c1b7bbc6acfeb34e044cca1838b877fbc7cee5 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Tue, 16 Jan 2024 14:16:02 -0800 Subject: [PATCH] formatting --- .../codebook/lvt/InstructionUnwrapper.java | 48 +++++++++++++++---- .../io/papermc/codebook/lvt/LvtNamer.java | 3 +- .../codebook/lvt/RootLvtSuggester.java | 28 ++++++++--- .../lvt/suggestion/ComplexGetSuggester.java | 35 ++++++++------ .../lvt/suggestion/FluentGetterSuggester.java | 6 ++- .../lvt/suggestion/GenericSuggester.java | 6 ++- .../codebook/lvt/suggestion/LvtSuggester.java | 12 ++++- .../lvt/suggestion/MathSuggester.java | 6 ++- .../lvt/suggestion/NewPrefixSuggester.java | 6 ++- .../lvt/suggestion/PositionsSuggester.java | 6 ++- .../suggestion/RecordComponentSuggester.java | 6 ++- .../SingleVerbBooleanSuggester.java | 6 ++- .../lvt/suggestion/SingleVerbSuggester.java | 6 ++- .../lvt/suggestion/StringSuggester.java | 6 ++- .../VerbPrefixBooleanSuggester.java | 6 ++- .../suggestion/context/AssignmentContext.java | 25 +++++++++- .../suggestion/context/SuggesterContext.java | 25 +++++++++- .../numbers/MthRandomSuggester.java | 6 ++- .../numbers/RandomSourceSuggester.java | 6 ++- .../papermc/codebook/report/ReportType.java | 3 +- .../io/papermc/codebook/report/Reports.java | 3 +- .../codebook/report/type/CheckCastWraps.java | 44 ++++++++++++++--- .../lvt/LvtAssignmentSuggesterTest.java | 13 +++-- 23 files changed, 247 insertions(+), 64 deletions(-) diff --git a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/InstructionUnwrapper.java b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/InstructionUnwrapper.java index 8d4d376..cb664c4 100644 --- a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/InstructionUnwrapper.java +++ b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/InstructionUnwrapper.java @@ -1,3 +1,25 @@ +/* + * codebook is a remapper utility for the PaperMC project. + * + * Copyright (c) 2023 Kyle Wood (DenWav) + * Contributors + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 3 only, no later versions. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + package io.papermc.codebook.lvt; import com.google.inject.Injector; @@ -28,10 +50,18 @@ public class InstructionUnwrapper { new Method("java/lang/Character", "charValue", "()C"))); private static final MethodMatcher UNWRAP_AFTER_CAST = new MethodMatcher(Set.of( - new Method("net/minecraft/world/level/block/state/BlockState", "getValue", "(Lnet/minecraft/world/level/block/state/properties/Property;)Ljava/lang/Comparable;"), - new Method("net/minecraft/world/level/storage/loot/LootContext", "getParamOrNull", "(Lnet/minecraft/world/level/storage/loot/parameters/LootContextParam;)Ljava/lang/Object;"), - new Method("net/minecraft/world/level/storage/loot/LootParams$Builder", "getOptionalParameter", "(Lnet/minecraft/world/level/storage/loot/parameters/LootContextParam;)Ljava/lang/Object;") - )); + new Method( + "net/minecraft/world/level/block/state/BlockState", + "getValue", + "(Lnet/minecraft/world/level/block/state/properties/Property;)Ljava/lang/Comparable;"), + new Method( + "net/minecraft/world/level/storage/loot/LootContext", + "getParamOrNull", + "(Lnet/minecraft/world/level/storage/loot/parameters/LootContextParam;)Ljava/lang/Object;"), + new Method( + "net/minecraft/world/level/storage/loot/LootParams$Builder", + "getOptionalParameter", + "(Lnet/minecraft/world/level/storage/loot/parameters/LootContextParam;)Ljava/lang/Object;"))); public InstructionUnwrapper(final Reports reports, final Injector reportsInjector) { this.reports = reports; @@ -55,10 +85,11 @@ public InstructionUnwrapper(final Reports reports, final Injector reportsInjecto return null; } - if (prev.getOpcode() == Opcodes.CHECKCAST) { final AbstractInsnNode tempPrev = prev.getPrevious(); - if (tempPrev.getOpcode() == Opcodes.INVOKEVIRTUAL || tempPrev.getOpcode() == Opcodes.INVOKEINTERFACE || tempPrev.getOpcode() == Opcodes.INVOKESTATIC) { + if (tempPrev.getOpcode() == Opcodes.INVOKEVIRTUAL + || tempPrev.getOpcode() == Opcodes.INVOKEINTERFACE + || tempPrev.getOpcode() == Opcodes.INVOKESTATIC) { final MethodInsnNode methodInsn = (MethodInsnNode) tempPrev; if (UNWRAP_AFTER_CAST.matches(methodInsn)) { prev = methodInsn; @@ -81,9 +112,10 @@ private MethodMatcher(final Set methods) { } boolean matches(final AbstractInsnNode insn) { - return insn instanceof final MethodInsnNode methodInsnNode && this.methodNames.contains(methodInsnNode.name) && this.methods.stream().anyMatch(m -> m.matches(methodInsnNode)); + return insn instanceof final MethodInsnNode methodInsnNode + && this.methodNames.contains(methodInsnNode.name) + && this.methods.stream().anyMatch(m -> m.matches(methodInsnNode)); } - } private record Method(String owner, String name, String desc, boolean itf) { diff --git a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/LvtNamer.java b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/LvtNamer.java index b763299..9b31148 100644 --- a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/LvtNamer.java +++ b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/LvtNamer.java @@ -70,7 +70,8 @@ public LvtNamer(final HypoContext context, final MappingSet mappings, final Repo this.lvtTypeSuggester = new LvtTypeSuggester(context); this.reports = reports; this.reportsInjector = Guice.createInjector(reports); - this.lvtAssignSuggester = new RootLvtSuggester(context, this.lvtTypeSuggester, this.reports, this.reportsInjector); + this.lvtAssignSuggester = + new RootLvtSuggester(context, this.lvtTypeSuggester, this.reports, this.reportsInjector); } public void processClass(final AsmClassData classData) throws IOException { diff --git a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/RootLvtSuggester.java b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/RootLvtSuggester.java index 3ea9feb..a6b511e 100644 --- a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/RootLvtSuggester.java +++ b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/RootLvtSuggester.java @@ -93,7 +93,10 @@ public final class RootLvtSuggester extends AbstractModule implements LvtSuggest private final InstructionUnwrapper unwrapper; public RootLvtSuggester( - final HypoContext hypoContext, final LvtTypeSuggester lvtTypeSuggester, final Reports reports, final Injector reportsInjector) { + final HypoContext hypoContext, + final LvtTypeSuggester lvtTypeSuggester, + final Reports reports, + final Injector reportsInjector) { this.hypoContext = hypoContext; this.lvtTypeSuggester = lvtTypeSuggester; this.injector = reportsInjector.createChildInjector(this); @@ -143,7 +146,8 @@ public String suggestName( } if (assignmentNode != null) { - final @Nullable String suggestedName = this.suggestNameFromFirstAssignment(ContainerContext.from(parent), new AssignmentContext(assignmentNode, lvt)); + final @Nullable String suggestedName = this.suggestNameFromFirstAssignment( + ContainerContext.from(parent), new AssignmentContext(assignmentNode, lvt)); if (suggestedName != null) { return determineFinalName(suggestedName, scopedNames); } @@ -176,8 +180,8 @@ public static String determineFinalName(final String suggestedName, final Set owners, final Set> methods, final MethodInsnNode node) { + private static boolean matches( + final Set owners, final Set> methods, final MethodInsnNode node) { return owners.contains(node.owner) && methods.stream() .anyMatch(e -> diff --git a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/FluentGetterSuggester.java b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/FluentGetterSuggester.java index 7bf4958..a79437d 100644 --- a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/FluentGetterSuggester.java +++ b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/FluentGetterSuggester.java @@ -57,7 +57,11 @@ public class FluentGetterSuggester implements LvtSuggester { @Override public @Nullable String suggestFromMethod( - final MethodCallContext call, final MethodInsnContext insn, final ContainerContext container, final AssignmentContext assignment, final SuggesterContext suggester) + final MethodCallContext call, + final MethodInsnContext insn, + final ContainerContext container, + final AssignmentContext assignment, + final SuggesterContext suggester) throws IOException { // I think it's best to only work with primitive types here, as other types should already have names // and this dramatically cuts down on the number of methods analyzed because we aren't filtering by diff --git a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/GenericSuggester.java b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/GenericSuggester.java index 95238a1..3fc7ddd 100644 --- a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/GenericSuggester.java +++ b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/GenericSuggester.java @@ -33,7 +33,11 @@ public class GenericSuggester implements LvtSuggester { @Override public @Nullable String suggestFromMethod( - final MethodCallContext call, final MethodInsnContext insn, final ContainerContext container, final AssignmentContext assignment, final SuggesterContext suggester) { + final MethodCallContext call, + final MethodInsnContext insn, + final ContainerContext container, + final AssignmentContext assignment, + final SuggesterContext suggester) { return switch (call.data().name()) { case "hashCode" -> "hashCode"; case "size" -> "size"; diff --git a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/LvtSuggester.java b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/LvtSuggester.java index b454108..6a632d7 100644 --- a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/LvtSuggester.java +++ b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/LvtSuggester.java @@ -35,13 +35,21 @@ public interface LvtSuggester { default @Nullable String suggestFromMethod( - final MethodCallContext call, final MethodInsnContext insn, final ContainerContext container, final AssignmentContext assignment, final SuggesterContext suggester) + final MethodCallContext call, + final MethodInsnContext insn, + final ContainerContext container, + final AssignmentContext assignment, + final SuggesterContext suggester) throws IOException { return null; } default @Nullable String suggestFromField( - final FieldCallContext call, final FieldInsnContext insn, final ContainerContext container, final AssignmentContext assignment, final SuggesterContext suggester) + final FieldCallContext call, + final FieldInsnContext insn, + final ContainerContext container, + final AssignmentContext assignment, + final SuggesterContext suggester) throws IOException { return null; } diff --git a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/MathSuggester.java b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/MathSuggester.java index a752afc..bc0d5d1 100644 --- a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/MathSuggester.java +++ b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/MathSuggester.java @@ -34,7 +34,11 @@ public class MathSuggester implements LvtSuggester { @Override public @Nullable String suggestFromMethod( - final MethodCallContext call, final MethodInsnContext insn, final ContainerContext container, final AssignmentContext assignment, final SuggesterContext suggester) + final MethodCallContext call, + final MethodInsnContext insn, + final ContainerContext container, + final AssignmentContext assignment, + final SuggesterContext suggester) throws IOException { final String methodName = call.data().name(); diff --git a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/NewPrefixSuggester.java b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/NewPrefixSuggester.java index 030e31a..cff1154 100644 --- a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/NewPrefixSuggester.java +++ b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/NewPrefixSuggester.java @@ -37,7 +37,11 @@ public class NewPrefixSuggester implements LvtSuggester { @Override public @Nullable String suggestFromMethod( - final MethodCallContext call, final MethodInsnContext insn, final ContainerContext container, final AssignmentContext assignment, final SuggesterContext suggester) + final MethodCallContext call, + final MethodInsnContext insn, + final ContainerContext container, + final AssignmentContext assignment, + final SuggesterContext suggester) throws IOException { final String methodName = call.data().name(); if (!hasPrefix(methodName, "new")) { diff --git a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/PositionsSuggester.java b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/PositionsSuggester.java index 1e0f387..5c91f60 100644 --- a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/PositionsSuggester.java +++ b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/PositionsSuggester.java @@ -54,7 +54,11 @@ public class PositionsSuggester implements LvtSuggester { @Override public @Nullable String suggestFromMethod( - final MethodCallContext call, final MethodInsnContext insn, final ContainerContext container, final AssignmentContext assignment, final SuggesterContext suggester) + final MethodCallContext call, + final MethodInsnContext insn, + final ContainerContext container, + final AssignmentContext assignment, + final SuggesterContext suggester) throws IOException { if ("net/minecraft/core/SectionPos".equals(insn.owner().name())) { return suggestNameForSectionPos(container.node(), call.data(), insn.node()); diff --git a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/RecordComponentSuggester.java b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/RecordComponentSuggester.java index 9f74135..2ce429d 100644 --- a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/RecordComponentSuggester.java +++ b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/RecordComponentSuggester.java @@ -36,7 +36,11 @@ public class RecordComponentSuggester implements LvtSuggester { @Override public @Nullable String suggestFromMethod( - final MethodCallContext call, final MethodInsnContext insn, final ContainerContext container, final AssignmentContext assignment, final SuggesterContext suggester) { + final MethodCallContext call, + final MethodInsnContext insn, + final ContainerContext container, + final AssignmentContext assignment, + final SuggesterContext suggester) { if (insn.owner().is(ClassKind.RECORD)) { return null; } diff --git a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/SingleVerbBooleanSuggester.java b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/SingleVerbBooleanSuggester.java index 92ca81a..00d5d92 100644 --- a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/SingleVerbBooleanSuggester.java +++ b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/SingleVerbBooleanSuggester.java @@ -59,7 +59,11 @@ public class SingleVerbBooleanSuggester implements LvtSuggester { @Override public @Nullable String suggestFromMethod( - final MethodCallContext call, final MethodInsnContext insn, final ContainerContext container, final AssignmentContext assignment, final SuggesterContext suggester) + final MethodCallContext call, + final MethodInsnContext insn, + final ContainerContext container, + final AssignmentContext assignment, + final SuggesterContext suggester) throws IOException { if (call.data().returnType() != PrimitiveType.BOOLEAN) { return null; diff --git a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/SingleVerbSuggester.java b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/SingleVerbSuggester.java index 4b59d9d..684aa4d 100644 --- a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/SingleVerbSuggester.java +++ b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/SingleVerbSuggester.java @@ -46,7 +46,11 @@ public class SingleVerbSuggester implements LvtSuggester { @Override public @Nullable String suggestFromMethod( - final MethodCallContext call, final MethodInsnContext insn, final ContainerContext container, final AssignmentContext assignment, final SuggesterContext suggester) { + final MethodCallContext call, + final MethodInsnContext insn, + final ContainerContext container, + final AssignmentContext assignment, + final SuggesterContext suggester) { final String methodName = call.data().name(); final @Nullable String prefix = tryMatchPrefix(methodName, SINGLE_VERB_PREFIXES); diff --git a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/StringSuggester.java b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/StringSuggester.java index b231b7f..4a5b948 100644 --- a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/StringSuggester.java +++ b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/StringSuggester.java @@ -34,7 +34,11 @@ public class StringSuggester implements LvtSuggester { @Override public @Nullable String suggestFromMethod( - final MethodCallContext call, final MethodInsnContext insn, final ContainerContext container, final AssignmentContext assignment, final SuggesterContext suggester) + final MethodCallContext call, + final MethodInsnContext insn, + final ContainerContext container, + final AssignmentContext assignment, + final SuggesterContext suggester) throws IOException { final String methodName = call.data().name(); diff --git a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/VerbPrefixBooleanSuggester.java b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/VerbPrefixBooleanSuggester.java index 2c7b3e6..32e3a03 100644 --- a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/VerbPrefixBooleanSuggester.java +++ b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/VerbPrefixBooleanSuggester.java @@ -43,7 +43,11 @@ public class VerbPrefixBooleanSuggester implements LvtSuggester { @Override public @Nullable String suggestFromMethod( - final MethodCallContext call, final MethodInsnContext insn, final ContainerContext container, final AssignmentContext assignment, final SuggesterContext suggester) { + final MethodCallContext call, + final MethodInsnContext insn, + final ContainerContext container, + final AssignmentContext assignment, + final SuggesterContext suggester) { if (call.data().returnType() != PrimitiveType.BOOLEAN) { return null; } diff --git a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/context/AssignmentContext.java b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/context/AssignmentContext.java index 511f881..3252d0b 100644 --- a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/context/AssignmentContext.java +++ b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/context/AssignmentContext.java @@ -1,7 +1,28 @@ +/* + * codebook is a remapper utility for the PaperMC project. + * + * Copyright (c) 2023 Kyle Wood (DenWav) + * Contributors + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 3 only, no later versions. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + package io.papermc.codebook.lvt.suggestion.context; import org.objectweb.asm.tree.LocalVariableNode; import org.objectweb.asm.tree.VarInsnNode; -public record AssignmentContext(VarInsnNode assignmentNode, LocalVariableNode lvt) { -} +public record AssignmentContext(VarInsnNode assignmentNode, LocalVariableNode lvt) {} diff --git a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/context/SuggesterContext.java b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/context/SuggesterContext.java index c2e3195..488f789 100644 --- a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/context/SuggesterContext.java +++ b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/context/SuggesterContext.java @@ -1,7 +1,28 @@ +/* + * codebook is a remapper utility for the PaperMC project. + * + * Copyright (c) 2023 Kyle Wood (DenWav) + * Contributors + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 3 only, no later versions. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + package io.papermc.codebook.lvt.suggestion.context; import dev.denwav.hypo.core.HypoContext; import io.papermc.codebook.lvt.LvtTypeSuggester; -public record SuggesterContext(HypoContext hypoContext, LvtTypeSuggester typeSuggester) { -} +public record SuggesterContext(HypoContext hypoContext, LvtTypeSuggester typeSuggester) {} diff --git a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/numbers/MthRandomSuggester.java b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/numbers/MthRandomSuggester.java index 25f3820..e1fd963 100644 --- a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/numbers/MthRandomSuggester.java +++ b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/numbers/MthRandomSuggester.java @@ -42,7 +42,11 @@ public class MthRandomSuggester implements LvtSuggester { @Override public @Nullable String suggestFromMethod( - final MethodCallContext call, final MethodInsnContext insn, final ContainerContext container, final AssignmentContext assignment, final SuggesterContext suggester) { + final MethodCallContext call, + final MethodInsnContext insn, + final ContainerContext container, + final AssignmentContext assignment, + final SuggesterContext suggester) { final String methodName = call.data().name(); if (!insn.ownerEqualTo(MTH_NAME)) { return null; diff --git a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/numbers/RandomSourceSuggester.java b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/numbers/RandomSourceSuggester.java index b001fec..fda3f44 100644 --- a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/numbers/RandomSourceSuggester.java +++ b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/numbers/RandomSourceSuggester.java @@ -55,7 +55,11 @@ public class RandomSourceSuggester implements LvtSuggester { @Override public @Nullable String suggestFromMethod( - final MethodCallContext call, final MethodInsnContext insn, final ContainerContext container, final AssignmentContext assignment, final SuggesterContext suggester) { + final MethodCallContext call, + final MethodInsnContext insn, + final ContainerContext container, + final AssignmentContext assignment, + final SuggesterContext suggester) { if (this.randomSourceClass == null) { return null; } diff --git a/codebook-reports/src/main/java/io/papermc/codebook/report/ReportType.java b/codebook-reports/src/main/java/io/papermc/codebook/report/ReportType.java index 02673d0..0d199e1 100644 --- a/codebook-reports/src/main/java/io/papermc/codebook/report/ReportType.java +++ b/codebook-reports/src/main/java/io/papermc/codebook/report/ReportType.java @@ -25,6 +25,5 @@ public enum ReportType { MISSING_METHOD_LVT_SUGGESTION, MISSING_METHOD_PARAM, - CHECK_CAST_WRAPS - ; + CHECK_CAST_WRAPS; } diff --git a/codebook-reports/src/main/java/io/papermc/codebook/report/Reports.java b/codebook-reports/src/main/java/io/papermc/codebook/report/Reports.java index 4d34f8e..af21af1 100644 --- a/codebook-reports/src/main/java/io/papermc/codebook/report/Reports.java +++ b/codebook-reports/src/main/java/io/papermc/codebook/report/Reports.java @@ -60,8 +60,7 @@ public Reports(final Path reportsDir, final Set typesToGenerate) { this.reports = Map.of( ReportType.MISSING_METHOD_LVT_SUGGESTION, new MissingMethodLvtSuggestion(), ReportType.MISSING_METHOD_PARAM, new MissingMethodParam(), - ReportType.CHECK_CAST_WRAPS, new CheckCastWraps() - ); + ReportType.CHECK_CAST_WRAPS, new CheckCastWraps()); } public void generateReports() throws IOException { diff --git a/codebook-reports/src/main/java/io/papermc/codebook/report/type/CheckCastWraps.java b/codebook-reports/src/main/java/io/papermc/codebook/report/type/CheckCastWraps.java index b398a77..c8c3428 100644 --- a/codebook-reports/src/main/java/io/papermc/codebook/report/type/CheckCastWraps.java +++ b/codebook-reports/src/main/java/io/papermc/codebook/report/type/CheckCastWraps.java @@ -1,3 +1,25 @@ +/* + * codebook is a remapper utility for the PaperMC project. + * + * Copyright (c) 2023 Kyle Wood (DenWav) + * Contributors + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 3 only, no later versions. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + package io.papermc.codebook.report.type; import java.util.Comparator; @@ -12,11 +34,20 @@ public class CheckCastWraps implements Report { @Override public String generate() { final StringBuilder sb = new StringBuilder(); - this.cache.entrySet().stream().sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).forEachOrdered(entry -> { - sb.append(entry.getKey().className).append("#").append(entry.getKey().methodName).append(" ") - .append(entry.getKey().descriptor).append(" ").append(entry.getKey().itf).append(" ") - .append(entry.getValue()).append("\n"); - }); + this.cache.entrySet().stream() + .sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())) + .forEachOrdered(entry -> { + sb.append(entry.getKey().className) + .append("#") + .append(entry.getKey().methodName) + .append(" ") + .append(entry.getKey().descriptor) + .append(" ") + .append(entry.getKey().itf) + .append(" ") + .append(entry.getValue()) + .append("\n"); + }); return sb.toString(); } @@ -25,6 +56,5 @@ public void report(final MethodInsnNode insn) { this.cache.compute(key, (k, v) -> v == null ? 1 : v + 1); } - private record CacheKey(String className, String methodName, String descriptor, boolean itf) { - } + private record CacheKey(String className, String methodName, String descriptor, boolean itf) {} } diff --git a/src/test/java/io/papermc/codebook/lvt/LvtAssignmentSuggesterTest.java b/src/test/java/io/papermc/codebook/lvt/LvtAssignmentSuggesterTest.java index 7ae4d67..ef043c5 100644 --- a/src/test/java/io/papermc/codebook/lvt/LvtAssignmentSuggesterTest.java +++ b/src/test/java/io/papermc/codebook/lvt/LvtAssignmentSuggesterTest.java @@ -96,8 +96,7 @@ class LvtAssignmentSuggesterTest { @BeforeEach void setup() throws Exception { - this.context = - HypoContext.builder().withContextProviders(this.provider).build(); + this.context = HypoContext.builder().withContextProviders(this.provider).build(); when(this.provider.findClass("java/util/List")).thenReturn(this.listClass); when(this.provider.findClass("java/util/Set")).thenReturn(this.setClass); @@ -107,8 +106,8 @@ void setup() throws Exception { when(this.randomSourceClass.name()).thenReturn(RANDOM_SOURCE_TYPE.asInternalName()); - this.suggester = - new RootLvtSuggester(this.context, new LvtTypeSuggester(this.context), this.reports, Guice.createInjector(this.reports)); + this.suggester = new RootLvtSuggester( + this.context, new LvtTypeSuggester(this.context), this.reports, Guice.createInjector(this.reports)); } @ParameterizedTest @@ -148,7 +147,11 @@ void testSuggester( final MethodInsnNode insn = new MethodInsnNode(Opcodes.INVOKEVIRTUAL, methodOwner, methodName, methodDescriptor); final @Nullable String result = this.suggester.suggestFromMethod( - MethodCallContext.create(method), MethodInsnContext.create(owner, insn), context, this.assignment, new SuggesterContext(this.context, this.suggester.lvtTypeSuggester)); + MethodCallContext.create(method), + MethodInsnContext.create(owner, insn), + context, + this.assignment, + new SuggesterContext(this.context, this.suggester.lvtTypeSuggester)); assertEquals(expectedName, result); }