Fix tag key generator output inconsistencies (#11218)
* Fix tag key generator output inconsistencies * use NonNull instead of NotNull for generated api --------- Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
This commit is contained in:
parent
70dfa467e7
commit
1cecc24cad
22 changed files with 1166 additions and 1186 deletions
|
@ -31,8 +31,6 @@ import net.minecraft.core.RegistrySetBuilder;
|
|||
import net.minecraft.data.registries.VanillaRegistries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.flag.FeatureElement;
|
||||
import net.minecraft.world.flag.FeatureFlags;
|
||||
import org.bukkit.MinecraftExperimental;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
@ -72,7 +70,7 @@ public class GeneratedKeyType<T, A> extends SimpleGenerator {
|
|||
}
|
||||
|
||||
private static final String CREATE_JAVADOC = """
|
||||
Creates a key for {@link $T} in a registry.
|
||||
Creates a key for {@link $T} in the registry {@code $L}.
|
||||
|
||||
@param key the value's key in the registry
|
||||
@return a new typed key
|
||||
|
@ -102,7 +100,7 @@ public class GeneratedKeyType<T, A> extends SimpleGenerator {
|
|||
.returns(returnType.annotated(NOT_NULL));
|
||||
if (this.publicCreateKeyMethod) {
|
||||
create.addAnnotation(EXPERIMENTAL_API_ANNOTATION); // TODO remove once not experimental
|
||||
create.addJavadoc(CREATE_JAVADOC, this.apiType);
|
||||
create.addJavadoc(CREATE_JAVADOC, this.apiType, this.registryKey.location().toString());
|
||||
}
|
||||
return create;
|
||||
}
|
||||
|
@ -190,8 +188,6 @@ public class GeneratedKeyType<T, A> extends SimpleGenerator {
|
|||
@Override
|
||||
protected JavaFile.Builder file(final JavaFile.Builder builder) {
|
||||
return builder
|
||||
.skipJavaLangImports(true)
|
||||
.addStaticImport(Key.class, "key")
|
||||
.indent(" ");
|
||||
.addStaticImport(Key.class, "key");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,15 +15,11 @@ import io.papermc.paper.registry.RegistryKey;
|
|||
import io.papermc.paper.registry.tag.TagKey;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.stream.Collectors;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistrySetBuilder;
|
||||
import net.minecraft.data.registries.VanillaRegistries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import org.bukkit.MinecraftExperimental;
|
||||
|
||||
|
@ -39,11 +35,6 @@ import static javax.lang.model.element.Modifier.STATIC;
|
|||
|
||||
public class GeneratedTagKeyType<T, A> extends SimpleGenerator {
|
||||
|
||||
private static final Map<ResourceKey<? extends Registry<?>>, RegistrySetBuilder.RegistryBootstrap<?>> VANILLA_REGISTRY_ENTRIES = VanillaRegistries.BUILDER.entries.stream()
|
||||
.collect(Collectors.toMap(RegistrySetBuilder.RegistryStub::key, RegistrySetBuilder.RegistryStub::bootstrap));
|
||||
|
||||
private static final Map<ResourceKey<? extends Registry<?>>, RegistrySetBuilder.RegistryBootstrap<?>> EXPERIMENTAL_REGISTRY_ENTRIES = Collections.emptyMap(); // Update for Experimental API
|
||||
|
||||
private static final Map<RegistryKey<?>, String> REGISTRY_KEY_FIELD_NAMES;
|
||||
static {
|
||||
final Map<RegistryKey<?>, String> map = new HashMap<>();
|
||||
|
@ -91,7 +82,7 @@ public class GeneratedTagKeyType<T, A> extends SimpleGenerator {
|
|||
.returns(returnType.annotated(NOT_NULL));
|
||||
if (this.publicCreateKeyMethod) {
|
||||
create.addAnnotation(EXPERIMENTAL_API_ANNOTATION); // TODO remove once not experimental
|
||||
create.addJavadoc(CREATE_JAVADOC, this.apiType, this.registryKey.registry().toString());
|
||||
create.addJavadoc(CREATE_JAVADOC, this.apiType, this.registryKey.location().toString());
|
||||
}
|
||||
return create;
|
||||
}
|
||||
|
@ -102,8 +93,8 @@ public class GeneratedTagKeyType<T, A> extends SimpleGenerator {
|
|||
.addJavadoc(Javadocs.getVersionDependentClassHeader("{@link $T#$L}"), RegistryKey.class, REGISTRY_KEY_FIELD_NAMES.get(this.apiRegistryKey))
|
||||
.addAnnotations(Annotations.CLASS_HEADER)
|
||||
.addMethod(MethodSpec.constructorBuilder()
|
||||
.addModifiers(PRIVATE)
|
||||
.build()
|
||||
.addModifiers(PRIVATE)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -117,8 +108,7 @@ public class GeneratedTagKeyType<T, A> extends SimpleGenerator {
|
|||
final Registry<T> registry = Main.REGISTRY_ACCESS.registryOrThrow(this.registryKey);
|
||||
|
||||
final AtomicBoolean allExperimental = new AtomicBoolean(true);
|
||||
registry.getTags().forEach(pair -> {
|
||||
final net.minecraft.tags.TagKey<T> nmsTagKey = pair.getFirst();
|
||||
registry.getTagNames().sorted(Formatting.alphabeticKeyOrder(nmsTagKey -> nmsTagKey.location().getPath())).forEach(nmsTagKey -> {
|
||||
final String fieldName = Formatting.formatKeyAsField(nmsTagKey.location().getPath());
|
||||
final FieldSpec.Builder fieldBuilder = FieldSpec.builder(tagKey, fieldName, PUBLIC, STATIC, FINAL)
|
||||
.initializer("$N(key($S))", createMethod.build(), nmsTagKey.location().getPath())
|
||||
|
@ -142,8 +132,6 @@ public class GeneratedTagKeyType<T, A> extends SimpleGenerator {
|
|||
@Override
|
||||
protected JavaFile.Builder file(final JavaFile.Builder builder) {
|
||||
return builder
|
||||
.skipJavaLangImports(true)
|
||||
.addStaticImport(Key.class, "key")
|
||||
.indent(" ");
|
||||
.addStaticImport(Key.class, "key");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -132,8 +132,7 @@ public class MobGoalGenerator extends SimpleGenerator {
|
|||
|
||||
@Override
|
||||
protected JavaFile.Builder file(JavaFile.Builder builder) {
|
||||
return builder
|
||||
.skipJavaLangImports(true);
|
||||
return builder;
|
||||
}
|
||||
|
||||
record DeprecatedEntry(Class<?> entity, String entryName, @Nullable String removalVersion,
|
||||
|
|
|
@ -7,8 +7,8 @@ import java.util.List;
|
|||
import io.papermc.paper.generated.GeneratedFrom;
|
||||
import net.minecraft.SharedConstants;
|
||||
import org.bukkit.MinecraftExperimental;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public final class Annotations {
|
||||
|
@ -26,10 +26,10 @@ public final class Annotations {
|
|||
return annotationSpecs;
|
||||
}
|
||||
|
||||
public static AnnotationSpec deprecatedVersioned(final @Nullable String version, boolean forRemoval) {
|
||||
AnnotationSpec.Builder annotationSpec = AnnotationSpec.builder(Deprecated.class);
|
||||
public static AnnotationSpec deprecatedVersioned(final @Nullable String version, final boolean forRemoval) {
|
||||
final AnnotationSpec.Builder annotationSpec = AnnotationSpec.builder(Deprecated.class);
|
||||
if (forRemoval) {
|
||||
annotationSpec.addMember("forRemoval", "$L", forRemoval);
|
||||
annotationSpec.addMember("forRemoval", "$L", true);
|
||||
}
|
||||
if (version != null) {
|
||||
annotationSpec.addMember("since", "$S", version);
|
||||
|
@ -46,7 +46,7 @@ public final class Annotations {
|
|||
|
||||
@ApiStatus.Experimental
|
||||
public static final AnnotationSpec EXPERIMENTAL_API_ANNOTATION = AnnotationSpec.builder(ApiStatus.Experimental.class).build();
|
||||
public static final AnnotationSpec NOT_NULL = AnnotationSpec.builder(NotNull.class).build();
|
||||
public static final AnnotationSpec NOT_NULL = AnnotationSpec.builder(NonNull.class).build();
|
||||
private static final AnnotationSpec SUPPRESS_WARNINGS = AnnotationSpec.builder(SuppressWarnings.class)
|
||||
.addMember("value", "$S", "unused")
|
||||
.addMember("value", "$S", "SpellCheckingInspection")
|
||||
|
|
|
@ -2,7 +2,6 @@ package io.papermc.generator.utils;
|
|||
|
||||
import com.mojang.serialization.Lifecycle;
|
||||
import io.papermc.generator.Main;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.HolderGetter;
|
||||
|
|
|
@ -4,7 +4,6 @@ import com.google.common.collect.HashMultimap;
|
|||
import com.google.common.collect.Multimap;
|
||||
import com.mojang.logging.LogUtils;
|
||||
import io.papermc.generator.Main;
|
||||
import io.papermc.generator.utils.Formatting;
|
||||
import java.util.Collections;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Map;
|
||||
|
@ -19,7 +18,6 @@ import net.minecraft.server.packs.PackType;
|
|||
import net.minecraft.server.packs.repository.BuiltInPackSource;
|
||||
import net.minecraft.server.packs.resources.MultiPackResourceManager;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.tags.TagManager;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
// collect all the tags by grabbing the json from the data-packs
|
||||
|
@ -50,9 +48,9 @@ public final class TagCollector {
|
|||
}
|
||||
|
||||
result.put(entry.value().getTagNames()
|
||||
.filter(tagKey -> tagKey.location().getPath().equals(path))
|
||||
.findFirst()
|
||||
.orElseThrow(), packId);
|
||||
.filter(tagKey -> tagKey.location().getPath().equals(path))
|
||||
.findFirst()
|
||||
.orElseThrow(), packId);
|
||||
});
|
||||
});
|
||||
return Collections.unmodifiableMap(result);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue