mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-24 18:07:39 +01:00
keep formatting around javadocs
This commit is contained in:
parent
f7a6263ce6
commit
d4de04ceb0
@ -222,7 +222,7 @@ public final class DataComponentTypes {
|
||||
* <li>can't be changed or removed in Anvil</li>
|
||||
* <li>is not styled with italics when displayed to player</li>
|
||||
* <li>does not show labels where applicable
|
||||
* (for example: banner markers, names in item frames)</li>
|
||||
* (for example: banner markers, names in item frames)</li>
|
||||
* </ul>
|
||||
*
|
||||
* @see #CUSTOM_NAME
|
||||
|
@ -165,7 +165,7 @@ public interface Biome extends OldEnum<Biome>, Keyed, net.kyori.adventure.transl
|
||||
|
||||
@NotNull
|
||||
private static Biome getBiome(@NotNull String key) {
|
||||
return Registry.BIOME.get(NamespacedKey.minecraft(key));
|
||||
return Registry.BIOME.getOrThrow(NamespacedKey.minecraft(key));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -74,7 +74,7 @@ public class RegistryFieldRewriter<T> extends SearchReplaceRewriter {
|
||||
while (referenceIterator.hasNext()) {
|
||||
Holder.Reference<T> reference = referenceIterator.next();
|
||||
|
||||
this.rewriteJavadocs(reference, metadata.indent(), builder);
|
||||
this.rewriteJavadocs(reference, metadata.replacedContent(), metadata.indent(), builder);
|
||||
|
||||
SingleFlagHolder requiredFeature = this.getRequiredFeature(reference);
|
||||
if (requiredFeature != null) {
|
||||
@ -98,7 +98,7 @@ public class RegistryFieldRewriter<T> extends SearchReplaceRewriter {
|
||||
}
|
||||
}
|
||||
|
||||
protected void rewriteJavadocs(Holder.Reference<T> reference, String indent, StringBuilder builder) {
|
||||
protected void rewriteJavadocs(Holder.Reference<T> reference, String replacedContent, String indent, StringBuilder builder) {
|
||||
}
|
||||
|
||||
protected boolean canPrintField(Holder.Reference<T> reference) {
|
||||
|
@ -1,30 +1,30 @@
|
||||
package io.papermc.generator.rewriter.types.simple.trial;
|
||||
|
||||
import java.util.List;
|
||||
import io.papermc.typewriter.parser.token.CharSequenceBlockToken;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
|
||||
class ConstantInfo {
|
||||
|
||||
private @MonotonicNonNull String constantName;
|
||||
private @MonotonicNonNull List<String> javadocs;
|
||||
private @MonotonicNonNull CharSequenceBlockToken token;
|
||||
|
||||
public void constantName(String name) {
|
||||
this.constantName = name;
|
||||
}
|
||||
|
||||
public void javadocs(List<String> javadocs) {
|
||||
this.javadocs = javadocs;
|
||||
public void javadocs(CharSequenceBlockToken token) {
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public String constantName() {
|
||||
return this.constantName;
|
||||
}
|
||||
|
||||
public List<String> javadocs() {
|
||||
return this.javadocs;
|
||||
public CharSequenceBlockToken javadocs() {
|
||||
return this.token;
|
||||
}
|
||||
|
||||
public boolean isComplete() {
|
||||
return this.constantName != null && this.javadocs != null;
|
||||
return this.constantName != null && this.token != null;
|
||||
}
|
||||
}
|
||||
|
@ -65,10 +65,10 @@ public class DataComponentTypesRewriter extends RegistryFieldRewriter<DataCompon
|
||||
TokenType.SINGLE_COMMENT
|
||||
);
|
||||
|
||||
private @MonotonicNonNull Map<String, List<String>> javadocsPerConstant;
|
||||
private @MonotonicNonNull Map<String, CharSequenceBlockToken> javadocsPerConstant;
|
||||
|
||||
private Map<String, List<String>> parseConstantJavadocs(String content) {
|
||||
Map<String, List<String>> map = new HashMap<>();
|
||||
private Map<String, CharSequenceBlockToken> parseConstantJavadocs(String content) {
|
||||
Map<String, CharSequenceBlockToken> map = new HashMap<>();
|
||||
|
||||
Lexer lex = new Lexer(content.toCharArray());
|
||||
SequenceTokens.wrap(lex, FORMAT_TOKENS)
|
||||
@ -76,7 +76,7 @@ public class DataComponentTypesRewriter extends RegistryFieldRewriter<DataCompon
|
||||
ConstantInfo info = new ConstantInfo();
|
||||
action
|
||||
.map(TokenType.JAVADOC, token -> {
|
||||
info.javadocs(((CharSequenceBlockToken) token).value());
|
||||
info.javadocs(((CharSequenceBlockToken) token));
|
||||
}, TokenTaskBuilder::asOptional)
|
||||
.skip(TokenType.PUBLIC).skip(TokenType.STATIC).skip(TokenType.FINAL)
|
||||
.skipQualifiedName(Predicate.isEqual(TokenType.JAVADOC))
|
||||
@ -144,20 +144,11 @@ public class DataComponentTypesRewriter extends RegistryFieldRewriter<DataCompon
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void rewriteJavadocs(Holder.Reference<DataComponentType<?>> reference, String indent, StringBuilder builder) {
|
||||
protected void rewriteJavadocs(Holder.Reference<DataComponentType<?>> reference, String replacedContent, String indent, StringBuilder builder) {
|
||||
String constantName = this.rewriteFieldName(reference);
|
||||
if (this.javadocsPerConstant.containsKey(constantName)) {
|
||||
builder.append(indent).append("/**");
|
||||
builder.append('\n');
|
||||
for (String line : this.javadocsPerConstant.get(constantName)) {
|
||||
builder.append(indent).append(" *");
|
||||
if (!line.isEmpty()) {
|
||||
builder.append(' ').append(line);
|
||||
}
|
||||
builder.append('\n');
|
||||
}
|
||||
builder.append(indent).append(" */");
|
||||
builder.append('\n');
|
||||
CharSequenceBlockToken token = this.javadocsPerConstant.get(constantName);
|
||||
builder.append(indent).append(replacedContent, token.pos(), token.endPos()).append('\n');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,6 @@ import io.papermc.typewriter.parser.token.TokenType;
|
||||
import io.papermc.typewriter.replace.SearchMetadata;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
@ -30,10 +29,10 @@ public class VillagerProfessionRewriter extends RegistryFieldRewriter<VillagerPr
|
||||
TokenType.SINGLE_COMMENT
|
||||
);
|
||||
|
||||
private @MonotonicNonNull Map<String, List<String>> javadocsPerConstant;
|
||||
private @MonotonicNonNull Map<String, CharSequenceBlockToken> javadocsPerConstant;
|
||||
|
||||
private Map<String, List<String>> parseConstantJavadocs(String content) {
|
||||
Map<String, List<String>> map = new HashMap<>();
|
||||
private Map<String, CharSequenceBlockToken> parseConstantJavadocs(String content) {
|
||||
Map<String, CharSequenceBlockToken> map = new HashMap<>();
|
||||
|
||||
Lexer lex = new Lexer(content.toCharArray());
|
||||
SequenceTokens.wrap(lex, FORMAT_TOKENS)
|
||||
@ -41,7 +40,7 @@ public class VillagerProfessionRewriter extends RegistryFieldRewriter<VillagerPr
|
||||
ConstantInfo info = new ConstantInfo();
|
||||
action
|
||||
.map(TokenType.JAVADOC, token -> {
|
||||
info.javadocs(((CharSequenceBlockToken) token).value());
|
||||
info.javadocs(((CharSequenceBlockToken) token));
|
||||
}, TokenTaskBuilder::asOptional)
|
||||
.skipQualifiedName(Predicate.isEqual(TokenType.JAVADOC))
|
||||
.map(TokenType.IDENTIFIER, token -> {
|
||||
@ -91,20 +90,11 @@ public class VillagerProfessionRewriter extends RegistryFieldRewriter<VillagerPr
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void rewriteJavadocs(Holder.Reference<VillagerProfession> reference, String indent, StringBuilder builder) {
|
||||
protected void rewriteJavadocs(Holder.Reference<VillagerProfession> reference, String replacedContent, String indent, StringBuilder builder) {
|
||||
String constantName = this.rewriteFieldName(reference);
|
||||
if (this.javadocsPerConstant.containsKey(constantName)) {
|
||||
builder.append(indent).append("/**");
|
||||
builder.append('\n');
|
||||
for (String line : this.javadocsPerConstant.get(constantName)) {
|
||||
builder.append(indent).append(" *");
|
||||
if (!line.isEmpty()) {
|
||||
builder.append(' ').append(line);
|
||||
}
|
||||
builder.append('\n');
|
||||
}
|
||||
builder.append(indent).append(" */");
|
||||
builder.append('\n');
|
||||
CharSequenceBlockToken token = this.javadocsPerConstant.get(constantName);
|
||||
builder.append(indent).append(replacedContent, token.pos(), token.endPos()).append('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user